GetVolumeInformation函数使用记录

函数原型

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](https://learn.microsoft.com/zh-cn/windows/win32/api/fileapi/nf-fileapi-getvolumeinformationa "GetVolumeInformationA 函数 (fileapi.h) - Win32 apps | Microsoft Learn") ![](https://i-blog.csdnimg.cn/direct/0b408b7fe6044d849895d6cf2fbda47e.png) 文档不短,其大概意思就是根据传入的盘符路径,获取盘符的各种信息; 接下来就是测试这个函数的功能; 直接上代码: 环境:vsstudio2019 ```cpp #include #include 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; } ``` 输出如下: ![](https://i-blog.csdnimg.cn/direct/8d7d987f0c544b599e98f0b1dce591df.png)

相关推荐
Mr_WangAndy1 天前
C++数据结构与算法_线性表_数组_概念动态数组,刷题
c++·二分查找·数组刷题·数组字符串逆序·零移动·有序数组的平方
阿猿收手吧!1 天前
【C++】jthread:优雅终止线程新方案
开发语言·c++
十五年专注C++开发1 天前
C++中各平台表示Debug的宏
开发语言·c++·debug
阿猿收手吧!1 天前
【C++】Ranges:彻底改变STL编程方式
开发语言·c++
Polaris北1 天前
第二十三天打卡
c++
0xSec笔记本挖呀瓦呀挖1 天前
Windows后门应急(二)--计划任务后门分析与处置|Windows取证分析
windows·安全·web安全·网络安全·系统安全·网络攻击模型·安全威胁分析
船神丿男人1 天前
C++:STL string(一)
开发语言·c++
程序员zgh1 天前
Linux 内存管理单元 MMU
linux·运维·服务器·c语言·开发语言·c++
Smart-Space1 天前
将copilot键映射为右control - 参考powertoys实现
c++
harrain1 天前
windows下载安装MySQL9.5的缺少Redistributable问题解决
windows·mysql