简体   繁体   English

如何以编程方式区分由subst命令创建的虚拟驱动器和实际可移动驱动器

[英]How to programmatically differentiate between Virtual Drive created by subst command and actual removable drive

When we attach removable drive, OS assigns drive letter to it. 当我们连接可移动驱动器时,操作系统会为其分配驱动器号。 Other way is to use subst command to map local folder to any drive. 其他方法是使用subst命令将本地文件夹映射到任何驱动器。 I am writing the hook to Explorer where I need to differentiate between these two drives. 我正在将钩子写入Explorer,在其中需要区分这两个驱动器。 I tried to use GetVolumePathName but it is not working correctly for virtual drives. 我尝试使用GetVolumePathName,但它不适用于虚拟驱动器。

I found the answer to the question by just adding one additional verification step. 我通过添加一个额外的验证步骤找到了问题的答案。

Suppose I mapped c:\\Folder1 to z:. 假设我将c:\\ Folder1映射到z:。

I have a path z:\\file1.txt. 我有一个路径z:\\ file1.txt。 If I try to get the mount point using API GetVolumePathName() then it fails so I can guess that z:\\ is nothing but the virtual drive which is pointing to some folder in other drive. 如果尝试使用API​​ GetVolumePathName()获取安装点,则安装失败,因此我可以猜测z:\\只是虚拟驱动器,它指向其他驱动器中的某个文件夹。

But If I have a path z:\\Folder2\\file1.txt then GetVolumePathName() gives me Mount Point as z:\\Folder2. 但是,如果我有路径z:\\ Folder2 \\ file1.txt,则GetVolumePathName()会将安装点指定为z:\\ Folder2。 I do not understand why. 我不理解为什么。 But to verify that whether it is actually pointing to any device volume I used API GetVolumeNameForVolumeMountPoint() to get volume name of Mount Point return above. 但是为了验证它是否实际上指向任何设备卷,我使用API​​ GetVolumeNameForVolumeMountPoint()来获取上面返回的安装点的卷名。 If Mount Point is for any device then it returns the actual volume name GUID of that device else it fails (for virtual drive). 如果Mount Point用于任何设备,则它将返回该设备的实际卷名GUID,否则它将失败(对于虚拟驱动器)。

Now to know if Mount Point return above is FIXED or REMOVABLE use GetDriveType() if it returns DRIVE_FIXED then it is fixed drive else DRIVE_REMOVABLE then it is removable. 现在知道上面的挂载点返回是FIXED还是REMOVABLE,如果GetDriveType()返回DRIVE_FIXED,则它是固定驱动器,否则,请使用GetDriveType();否则返回DRIVE_REMOVABLE,则可以移动。

It solved my purpose. 它解决了我的目的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM