Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get drive information by volume id

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"];
}
like image 421
user844541 Avatar asked Apr 17 '12 06:04

user844541


People also ask

How do I Find my drive information?

Open the System Information file. In the System Information window, click the + symbol next to Components. Click the + next to Storage and click Drives. In the right-side of the window, you see information about the hard drive including its capacity and serial number.

What is a volume ID?

The volume identifier is a name that is given to an optical volume when it is created or initialized. Depending on the media format, the volume identifier can be up to 32 characters in length. On the system, applications accessing data from the optical volume often refer to it by its volume identifier.


2 Answers

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.

like image 78
MSalters Avatar answered Oct 21 '22 16:10

MSalters


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

like image 39
Likurg Avatar answered Oct 21 '22 16:10

Likurg