How to get drive information by volume id

user844541 picture user844541 · Apr 17, 2012 · Viewed 14.3k times · Source

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"];
}

Answer

Likurg picture Likurg · Apr 17, 2012

Try use this

System.Management.ManagementObjectSearcher ms =
new System.Management.ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");
foreach (ManagementObject mo in ms.Get())
{
    //Find by ID
}

For details reed this Win32_DiskDrive class