Windows API 第20篇 GetVolumeNameForVolumeMountPoint

函数原型:

BOOL GetVolumeNameForVolumeMountPoint(
                                                                            IN  LPCTSTR lpszVolumeMountPoint, // volume mount point or directory
                                                                            OUT  LPTSTR lpszVolumeName,        // volume name buffer
                                                                            IN  DWORD cchBufferLength         // size of volume name buffer);


此函数根据挂载点或者根目录获取相关连的卷的唯一标志符(GUID),也就是得到像
\\?\Volume{fe04a016-a8fc-11e4-824b-806e6f6e6963}\ 这样的字符

The GetVolumeNameForVolumeMountPoint function takes a volume mount point or root directory and returns the corresponding unique volume name.
举例:
1)传入更目录 

CHAR szVolumeName[MAX_PATH] = { 0 };

BOOL bRet = GetVolumeNameForVolumeMountPointA("C:\\", szVolumeName, MAX_PATH); 


2)传入一个已存在的卷的挂载点,假设设置了D盘的挂载点为 C:\test\

CHAR szVolumeName[MAX_PATH] = { 0 };

BOOL bRet = GetVolumeNameForVolumePountPointA("C:\\test\\, szVolumeName, MAX_PATH");

标注:

The lpszVolumeMountPoint input string may be a drive letter with appended backslash (\), such as "D:\". Alternatively, it may be a path to a volume mount point, again with appended backslash (\), such as "c:\mnt\edrive\".

关于Unique Volume Name介绍:

Two factors can make it hard to reliably mount a specific volume at a specified volume mount point across operating system restarts. One factor is that two different volumes can have the same label, which makes them indistinguishable except by drive letter. The other factor is that drive letters do not necessarily remain the same. If a computer's administrator does not use the Disk Administrator to enforce drive letters, then drive letters can change as drives are removed from or added to the system.

To solve this problem, the system refers to volumes to be mounted with unique volume names. These are strings of this form:

"\\?\Volume{GUID}\"

where GUID is a globally unique identifier (GUID) that identifies the volume. The \\?\ turns off path parsing and is ignored as part of the path, as discussed in Path Lengths. Note the trailing backslash. All volume mount point functions that take a unique volume name as a parameter require the trailing backslash; all volume mount point functions that return a unique volume name provide the trailing backslash. You can use CreateFile to open a volume by referring to its unique volume name, but without a trailing backslash. When using CreateFile, a unique volume name with a backslash refers to the root directory of the volume.

The operating system assigns a unique volume name to a volume when the computer first encounters it, for example during formatting or installation. The volume mount point functions use unique volume names to refer to volumes. To learn the unique volume name of any drive, use the GetVolumeNameForVolumeMountPoint function.

转载于:https://www.cnblogs.com/priarieNew/p/9755473.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值