How to get disk information by volume id

I have a txt file with volume id.

I need to get disk information (drive letter, disk size, etc.) from the disk volume identifier (Windows):

The volume identifier is in the following format:

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

The drive can be a removable / local drive

It does not matter how the information is extracted (it can be a script, cpp, C #, java code).

EDIT:

I tried to use DriveInfo, Win32_LogicalDisk, Win32_Volume, Win32_PnpDevices - but I could not find this strange identifier ... in all cases the id has a differentrent format

UPDATE:

Learned how to do it.

you can list Win32_Volume as follows:

 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"]; } 
+5
source share
4 answers

Volume Size, etc. easy. Just use regular Win32 methods. Any function that takes "C:" as a disk will also accept the GUID volume path (because the one that a \\?\Volume{XXX} correctly called).

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

+2
source

Try using

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

See the Win32_DiskDrive class for more details.

+2
source

There is an API function for this: GetVolumePathNamesForVolumeName

It returns an array with a terminating zero to allow multiple mount points. If you have only one mount point (typical), you can read it as a regular line with zero completion.

This is more efficient if you list disks / volumes, which can lead to the fact that idle disks will be deployed.

+1
source

You can use the DriveInfo.GetDrives Method to get disk information. Here is sample code from MSDN

 DriveInfo[] allDrives = DriveInfo.GetDrives(); foreach (DriveInfo d in allDrives) { Console.WriteLine("Drive {0}", d.Name); Console.WriteLine(" File type: {0}", d.DriveType); if (d.IsReady == true) { Console.WriteLine(" Volume label: {0}", d.VolumeLabel); Console.WriteLine(" File system: {0}", d.DriveFormat); Console.WriteLine( " Available space to current user:{0, 15} bytes", d.AvailableFreeSpace); Console.WriteLine( " Total available space: {0, 15} bytes", d.TotalFreeSpace); Console.WriteLine( " Total size of drive: {0, 15} bytes ", d.TotalSize); } } 
-2
source

Source: https://habr.com/ru/post/982740/


All Articles