函数原型
BOOL GetVolumeInformationA(
in, optional LPCSTR lpRootPathName,
out, optional LPSTR lpVolumeNameBuffer,
in DWORD nVolumeNameSize,
out, optional LPDWORD lpVolumeSerialNumber,
out, optional LPDWORD lpMaximumComponentLength,
out, optional LPDWORD lpFileSystemFlags,
out, optional LPSTR lpFileSystemNameBuffer,
in DWORD nFileSystemNameSize
);
在windows中有两种
普通:GetVolumeInformationA
宽字符版:GetVolumeInformationW
这里我以普通GetVolumeInformationA为例;
先看官方文档解释
官方文档:GetVolumeInformationA 函数 (fileapi.h) - Win32 apps | Microsoft Learn

文档不短,其大概意思就是根据传入的盘符路径,获取盘符的各种信息;
接下来就是测试这个函数的功能;
直接上代码:
环境:vsstudio2019
cpp
#include <windows.h>
#include <stdio.h>
int main() {
char volumeName[MAX_PATH];
char fileSystemName[MAX_PATH];
DWORD serialNumber;
DWORD maxComponentLength;
DWORD fileSystemFlags;
// 获取F盘的信息(注意:其中的F填你自己要查询的盘符)
if (!GetVolumeInformationA("F:\\", volumeName, MAX_PATH, &serialNumber, &maxComponentLength, &fileSystemFlags, fileSystemName, MAX_PATH)) {
printf("获取F盘信息失败,错误码:%d\n", GetLastError());
return 1;
}
// 输出F盘的相关信息
printf("盘符F的卷标名称:%s\n", volumeName);
printf("盘符F的序列号:%lu\n", serialNumber);
printf("盘符F的文件系统名称:%s\n", fileSystemName);
printf("盘符F的最大组件长度:%lu\n", maxComponentLength);
printf("盘符F的文件系统标志:%lu\n", fileSystemFlags);
return 0;
}
输出如下:
