如何获得由卷ID驱动器的信息 [英] How to get drive information by volume id

查看:209
本文介绍了如何获得由卷ID驱动器的信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有卷ID在其中的一个txt文件。



我需要从驱动器卷ID驱动器信息(驱动器盘符,驱动器大小等) (Windows)中:



卷id的格式如下:

  \\?\Volume {XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} 

该驱动器可以是可拆卸/本地磁盘



没关系的信息是如何获取(也可能是脚本,CPP,C#,Java代码)。



编辑:



我试图用DriveInfo,的Win32_LogicalDisk,Win32_Volume,Win32_PnpDevices - 但我找不到这个奇怪的ID ......在所有情况下的ID有differrent格式



更新:

$ b $ ; b

发现了如何做到这一点。



您可以枚举Win32_Volume是这样的:

  ManagementObjectSearcher毫秒=新ManagementObjectSearcher(SELECT * FROM Win32_Volume); 
的foreach(MO的ManagementObject在ms.Get())
{
VAR GUID = MO [的DeviceID]的ToString()。

如果(GUID == myGuid)
返回莫[驱动器号];
}


解决方案

音量大小,等等很容易。只需使用普通的Win32方法。接受任何函数C:为驱动器也将接受在卷GUID路径(因为这是一个 \\ \\\?\Volume {XXX} 正确调用)。



在驱动器盘符是一个有点棘手,因为可能0,1或更多的驱动器字母。你需要调用 FindFirstVolumeMountPoint / FindNextVolumeMountPoint / FindVolumeMountPointClose 让所有的人。


I have a txt file with volume id's in it.

I need to get drive info (drive letter, drive size, etc.) from the drive volume id (Windows):

the volume id is in the following format:

\\?\Volume{XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}

The drive can be Removable/local disk

It doesn't matter how the info is retrieved (it could be script, cpp ,c#, java code).

EDIT:

I tried to use DriveInfo, Win32_LogicalDisk, Win32_Volume, Win32_PnpDevices - but I couldn't find this weird id... in all cases the id has a differrent format

UPDATE:

Found out how to do it.

you can enumerate Win32_Volume like this:

ManagementObjectSearcher ms = new ManagementObjectSearcher("Select * from Win32_Volume");    
foreach(ManagementObject mo in ms.Get())   
{
    var guid = mo["DeviceID"].ToString();

    if(guid == myGuid)
        return mo["DriveLetter"];
}

解决方案

Volume size, etcetera is easy. Just use the normal Win32 methods. Any function that accepts "C:" as a drive will also accept the volume GUID path (because that's what a \\?\Volume{XXX} is properly called).

The "drive letter" is a bit trickier as there may be 0, 1 or more drive letters. You need to call FindFirstVolumeMountPoint / FindNextVolumeMountPoint / FindVolumeMountPointClose to get all of them.

这篇关于如何获得由卷ID驱动器的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆