WMI 获取驱动器号与物理驱动器路径的关联,错过 CDROM
我正在运行以下 WMI 脚本来获取系统上的驱动器号和物理驱动器之间的关联,但由于某种原因它省略了 CDROM/DVD-ROM。有人可以告诉我如何获得这些吗?
ComputerName = "."
Set wmiServices = GetObject _
("winmgmts:{impersonationLevel=Impersonate}!//" & ComputerName)
Set wmiDiskDrives = wmiServices.ExecQuery _
("SELECT DeviceID FROM Win32_DiskDrive")
For Each wmiDiskDrive In wmiDiskDrives
strEscapedDeviceID = _
Replace(wmiDiskDrive.DeviceID, "\", "\\", 1, -1, vbTextCompare)
Set wmiDiskPartitions = wmiServices.ExecQuery _
("ASSOCIATORS OF {Win32_DiskDrive.DeviceID=""" & _
strEscapedDeviceID & """} WHERE " & _
"AssocClass = Win32_DiskDriveToDiskPartition")
For Each wmiDiskPartition In wmiDiskPartitions
Set wmiLogicalDisks = wmiServices.ExecQuery _
("ASSOCIATORS OF {Win32_DiskPartition.DeviceID=""" & _
wmiDiskPartition.DeviceID & """} WHERE " & _
"AssocClass = Win32_LogicalDiskToPartition")
For Each wmiLogicalDisk In wmiLogicalDisks
WScript.Echo wmiLogicalDisk.DeviceID & " = " & wmiDiskDrive.DeviceID
Next
Next
Next
I'm 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 = "."
Set wmiServices = GetObject _
("winmgmts:{impersonationLevel=Impersonate}!//" & ComputerName)
Set wmiDiskDrives = wmiServices.ExecQuery _
("SELECT DeviceID FROM Win32_DiskDrive")
For Each wmiDiskDrive In wmiDiskDrives
strEscapedDeviceID = _
Replace(wmiDiskDrive.DeviceID, "\", "\\", 1, -1, vbTextCompare)
Set wmiDiskPartitions = wmiServices.ExecQuery _
("ASSOCIATORS OF {Win32_DiskDrive.DeviceID=""" & _
strEscapedDeviceID & """} WHERE " & _
"AssocClass = Win32_DiskDriveToDiskPartition")
For Each wmiDiskPartition In wmiDiskPartitions
Set wmiLogicalDisks = wmiServices.ExecQuery _
("ASSOCIATORS OF {Win32_DiskPartition.DeviceID=""" & _
wmiDiskPartition.DeviceID & """} WHERE " & _
"AssocClass = Win32_LogicalDiskToPartition")
For Each wmiLogicalDisk In wmiLogicalDisks
WScript.Echo wmiLogicalDisk.DeviceID & " = " & wmiDiskDrive.DeviceID
Next
Next
Next
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
考虑到迄今为止的所有评论,这里有一个脚本添加了列出 CD-Rom 驱动器的功能。
Considering all of the comments thus far, here is a script that adds the capability to list CD-Rom drives.
我认为您需要使用
Win32_CDROMDrive
WMI 类来访问 CD-ROM 信息。上面的代码正在Win32_DiskDrive
类中查找物理驱动器,它不包括 CD_ROM您可以使用其他行来获取类似的数据 - 但给定的 CD-ROM 不具有分区特征,但情况不同您当前的代码确实
相反,我认为这个不同的 VBS 可能 可以做您想要的事情 - 可能部分,因为我认为分区信息与您无关。
vbs版本
vba 版本
I think you wouldn need to use the
Win32_CDROMDrive
WMI class to access CD-ROM info. The code you have above is looking for physical drives in theWin32_DiskDrive
class, it excludes CD_ROMYou could additional lines to get similar data - but not the same given CD-ROMs don't have the Partition characteristics that your current code does
Instead I think this different VBS may do what you want - the may part as I dont think the partition info is relevant to you.
vbs version
vba version