EDN Admin
Well-known member
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
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