Home
Tutorials
Code Snippets
Code Samples
Downloads
Links

The Blog
Our Projects
About
Contact

::Add RageStorm to Favorites!::

The Blog | Our Projects | Guest Book | About | Contact

 
Code Snippet - Drive Volume
Author:Arkon
Category:Win32API
File Size:~ 1.14 KB
Uploaded at:27-Nov-02 03:21:10 pm
Description:
  Gets the volume of a specified drive.
  
// This is the way to retrieve info of a logical drive.

void GetRootInfo(char *root)
{
 DWORD LongFNameLen = 0, flags = 0;
 char volume[32], FATName[32];
 DWORD serialnum = 0;
 FillMemory(volume, 32, 0);
 FillMemory(FATName, 32, 0);
 UINT oldErrMode = SetErrorMode(SEM_FAILCRITICALERRORS); // Disables the system from telling the user to insert a CD or a floppy disc if needed.
 BOOL res = GetVolumeInformation(root, volume, 32, &serialnum, &LongFNameLen, &flags, FATName, 32);
 if (res != 0)
 {
  // Convert serial number to a display form
  char tmp[256];
  FillMemory(tmp, 256, '0');
  char serial[16];
  FillMemory(serial, 16, 0);
  ltoa(serialnum, serial, 16);
  CopyMemory(&tmp[8 - strlen(serial)], serial, strlen(serial));
  for (int i = 0; i < 4; i++)
   serial[i] = toupper(tmp[i]);
  serial[i++] = '-';
  for (; i < 9; i++)
   serial[i]  = toupper(tmp[i-1]);
 
  FillMemory(tmp, 256, 0);
  sprintf(tmp, "FAT Name:%s, Root:%s, RootVolume:%s, RootSerial:%s", FATName, root, volume, serial);
  MessageBox(NULL, tmp, "Volume Information", MB_OK);
 }
 SetErrorMode(oldErrMode);
}

// Usage:
 GetRootInfo("C:\\"); // Voila :)
NOTE:
Comments that will hurt anyone in any way will be deleted.
Don't ask for features, advertise or curse.
If you want to leave a message to the author use the contacts,
if you have any question in relation to your comments please use the forum.
Comments which violate any of these requests will be deleted without further
notice. Use the comment system decently.

Post your comment:
Name:
email:
Comment:
::Top 5 Tutorials::
Embedded Python[105418]
2D Rotated Rectangles Collision Detection[78723]
Keyboard Hook[68414]
UDP[52506]
HTTP Proxy[35823]

::Top 5 Samples::
2D ColDet Rotated Rectangles[10562]
PS2 Mouse Driver[6063]
Wave Format Player[4945]
Reading FAT12[4828]
CodeGuru[4521]


All rights reserved to RageStorm © 2009