How to get the device instance id of a disk or volume?
-
I am developing a software where I store the Instance ID of every disk in the system. How can I get the Instance ID from a disk number? e.g I want Instance ID of DIsk0 DIsk1 etc.? here is what I am doing 1] SetupDiClassGuidsFromNameA("DiskDrive",***); to get the GUID for disk drives 2]SetupDiEnumDeviceInf(***) to enumrate all the disks.This gives me Instance ID's of all the disks but how can I get the device instance ID of spesific disk(like Disk0)?
-
I am developing a software where I store the Instance ID of every disk in the system. How can I get the Instance ID from a disk number? e.g I want Instance ID of DIsk0 DIsk1 etc.? here is what I am doing 1] SetupDiClassGuidsFromNameA("DiskDrive",***); to get the GUID for disk drives 2]SetupDiEnumDeviceInf(***) to enumrate all the disks.This gives me Instance ID's of all the disks but how can I get the device instance ID of spesific disk(like Disk0)?
Your best bet is to use WMI. The following code was pulled from Microsoft's WMI Code Creator (you can download it from their website):
strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set colItems = objWMIService.ExecQuery( _ "SELECT * FROM Win32_DiskDrive",,48) For Each objItem in colItems Wscript.Echo "-----------------------------------" Wscript.Echo "Win32_DiskDrive instance" Wscript.Echo "-----------------------------------" Wscript.Echo "DeviceID: " & objItem.DeviceID Next
This is a .vbs script, but the WMI Code Creator will output to VB.NET and C# as well. Hope this helps...