WMI to get drive letter association with physical drive path, misses CDROMs

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Im running the following WMI script to get the associations between drive letters and physical drives on the system, but for some reason it omits CDROMs/DVD-ROMs. Can someone tell me how to get those as well?

ComputerName = "."<br/>
Set wmiServices = GetObject _<br/>
("winmgmts:{impersonationLevel=Impersonate}!//" & ComputerName)<br/>
Set wmiDiskDrives = wmiServices.ExecQuery _<br/>
("SELECT DeviceID FROM Win32_DiskDrive")<br/>
<br/>
For Each wmiDiskDrive In wmiDiskDrives<br/>
strEscapedDeviceID = _<br/>
Replace(wmiDiskDrive.DeviceID, "", "\", 1, -1, vbTextCompare)<br/>
Set wmiDiskPartitions = wmiServices.ExecQuery _<br/>
("ASSOCIATORS OF {Win32_DiskDrive.DeviceID=""" & _<br/>
strEscapedDeviceID & """} WHERE " & _<br/>
"AssocClass = Win32_DiskDriveToDiskPartition")<br/>
<br/>
For Each wmiDiskPartition In wmiDiskPartitions<br/>
Set wmiLogicalDisks = wmiServices.ExecQuery _<br/>
("ASSOCIATORS OF {Win32_DiskPartition.DeviceID=""" & _<br/>
wmiDiskPartition.DeviceID & """} WHERE " & _<br/>
"AssocClass = Win32_LogicalDiskToPartition")<br/>
<br/>
For Each wmiLogicalDisk In wmiLogicalDisks<br/>
WScript.Echo wmiLogicalDisk.DeviceID & " = " & wmiDiskDrive.DeviceID<br/>
Next<br/>
Next<br/>
Next<br/>
<br/>


View the full article
 
Back
Top