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 08: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[117060]
2D Rotated Rectangles Collision Detection[88986]
Keyboard Hook[77325]
UDP[65878]
HTTP Proxy[41217]

::Top 5 Samples::
2D ColDet Rotated Rectangles[11561]
PS2 Mouse Driver[6959]
Wave Format Player[5792]
Reading FAT12[5620]
CodeGuru[5359]


All rights reserved to RageStorm © 2009