I am using WMI to get all inserted USB disks manufactures names. The code works great but I have a problem how can I determine witch drive letter a certain disk has... I can get only the device name e.g
(\\.\PhysicalDrive1) ... how can I translate this in a normal drive letter?
If you are getting values like
\\.\PHYSICALDRIVE1
means which you are using theWin32_DiskDrive
wmi class and theDeviceID
Property , so in order to get the Drive letter you must use an ASSOCIATORS class, which will create a link between the wmi classes with contain the information which you are looking for (Win32_LogicalDisk
) and the class which you are using (Win32_DiskDrive
).So you must do something like this
Win32_DiskDrive
-> Win32_DiskDriveToDiskPartition -> Win32_DiskPartition -> Win32_LogicalDiskToPartition ->Win32_LogicalDisk
Check this sample function