如何获取驱动器号的卷名
示例:我如何获得G:/
的卷名感谢您的帮助
答案 0 :(得分:2)
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
传递卷根路径(例如“C:\”),获取大量信息(包括卷名,也称为卷标)。
自Windows 2000以来可用。
答案 1 :(得分:2)
使用以下代码段:
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);
}
在我的系统上,输出为:
Volume Name: Zion
Serial Number: 112749257
File System Name: NTFS
Max Component Length: 255
答案 2 :(得分:0)
您可以从以下代码中获取:
BOOL WINAPI GetVolumeNameForVolumeMountPoint(
__in LPCTSTR lpszVolumeMountPoint,
__out LPTSTR lpszVolumeName,
__in DWORD cchBufferLength
);
进一步参考Click here