0

我正在尝试使用 WMI 调用获取驱动器接口类型和驱动器号,但驱动器号始终作为机器上最后分配的驱动器返回

任何人都可以帮忙吗?

'On Error Resume Next
 Option Explicit

 Dim strComputer, objWMIService, colIDiskDrive, objDiskDrive, colLogicalDisk, objLogicalDisk, strDriveLetter, strPNPDeviceID, strDiskLetter, strInterfaceType

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colIDiskDrive = objWMIService.ExecQuery("Select * from Win32_DiskDrive",,48)

For Each objDiskDrive in colIDiskDrive
strPNPDeviceID = objDiskDrive.PNPDeviceID
strInterfaceType = objDiskDrive.InterfaceType
Set colLogicalDisk = objWMIService.ExecQuery("Select * from Win32_LogicalDisk") 

For Each objLogicalDisk in colLogicalDisk
        strDiskLetter = objLogicalDisk.Name
Next

Wscript.Echo strInterfaceType & " " & strDiskLetter
Next
4

1 回答 1

0

如果我得到它,我将 Echo 移动到第二个/嵌套的 For/Next 循环中:

Option Explicit

Dim strComputer, objWMIService, colIDiskDrive, objDiskDrive, colLogicalDisk, objLogicalDisk, strDriveLetter, strPNPDeviceID, strDiskLetter, strInterfaceType

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colIDiskDrive = objWMIService.ExecQuery("Select * from Win32_DiskDrive",,48)

For Each objDiskDrive in colIDiskDrive
    strPNPDeviceID = objDiskDrive.PNPDeviceID
    strInterfaceType = objDiskDrive.InterfaceType
    Set colLogicalDisk = objWMIService.ExecQuery("Select * from Win32_LogicalDisk") 

    For Each objLogicalDisk in colLogicalDisk
        strDiskLetter = objLogicalDisk.Name
        Wscript.Echo strInterfaceType & " " & strDiskLetter
    Next
Next
于 2013-01-23T17:00:20.567 回答