开发者

why dont i get volume name for usb pen drive

开发者 https://www.devze.com 2023-01-04 09:41 出处:网络
How can i get volume name for drive letter example: 开发者_运维技巧how can i get volume name for G:/

How can i get volume name for drive letter

example: 开发者_运维技巧how can i get volume name for G:/

Thank you for any help


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.


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


You can get it from this code:

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

For further reference Click here

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号