views:

46

answers:

3

Dear all

How can i get volume name for drive letter

example: how can i get volume name for G:/

Thank you for any help

+2  A: 
BOOL WINAPI GetVolumeInformation(
  __in_opt   LPCTSTR lpRootPathName,
  __out      LPTSTR lpVolumeNameBuffer,
  __in       DWORD nVolumeNameSize,
  __out_opt  LPDWORD lpVolumeSerialNumber,
  __out_opt  LPDWORD lpMaximumComponentLength,
  __out_opt  LPDWORD lpFileSystemFlags,
  __out      LPTSTR lpFileSystemNameBuffer,
  __in       DWORD nFileSystemNameSize
);

http://msdn.microsoft.com/en-us/library/aa364993(v=VS.85).aspx

Pass the volume root path (such as "C:\") in, get a lot of information (including the volume name, also called the volume label) out.

Available since Windows 2000.

MaxVT
+1  A: 

You can get it from this code:

BOOL WINAPI GetVolumeNameForVolumeMountPoint(
  __in   LPCTSTR lpszVolumeMountPoint,
  __out  LPTSTR lpszVolumeName,
  __in   DWORD cchBufferLength
);

For further reference Click here

Rupeshit
+1  A: 

Use the following snippet:

TCHAR volumeName[MAX_PATH + 1] = { 0 };
TCHAR fileSystemName[MAX_PATH + 1] = { 0 };
DWORD serialNumber = 0;
DWORD maxComponentLen = 0;
DWORD fileSystemFlags = 0;

if (GetVolumeInformation(
    _T("C:\\"),
    volumeName,
    ARRAYSIZE(volumeName),
    &serialNumber,
    &maxComponentLen,
    &fileSystemFlags,
    fileSystemName,
    ARRAYSIZE(fileSystemName)))
{
_tprintf(_T("Volume Name: %s\n"), volumeName);
_tprintf(_T("Serial Number: %lu\n"), serialNumber);
_tprintf(_T("File System Name: %s\n"), fileSystemName);
_tprintf(_T("Max Component Length: %lu\n"), maxComponentLen);
}

On my system the output was:

Volume Name: Zion
Serial Number: 112749257
File System Name: NTFS
Max Component Length: 255
Favonius