GetVolumeInformation

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);
}

serialNumber是双字,所以%d是正常显示的,所以用了%lu。
ARRAYSIZE 是宏: #define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))。
volumeName是卷标名
serialNumber是卷标序列号(表示为0xAAAAAAAA)
maxComponentLen 最长文件名

代码来源:http://www.dreamincode.net/forums/topic/70779-howto-use-msdn-functions-%26gt%3B-getvolumeinformation/page__view__findpost__p__457887

标签: C语言, Windows API

添加新评论