我继承了附加的脚本,现在我需要打印出SerialNumber。 我想我距离2-3行,但是我是VBScript的新手。 请让我知道我缺少哪一行。 我正在尝试为USB设备打印序列号。
我正在查看以下内容:https://docs.microsoft.com/en-us/windows/desktop/CIMWin32Prov/win32-diskdrive,并认为SerialNumber是我所需要的。
' VB Script Document 28556806.vbs
option explicit
On Error Goto 0
Dim ComputerName, strRslt, strQuery
Dim wmiServices _
, wmiDiskDrives, wmiDiskDrive _
, wmiDiskPartitions, wmiDiskPartition _
, wmiLogicalDisks, wmiLogicalDisk
strRslt = Wscript.ScriptName _
& vbTab & "Drive letters associated with disk drives" _
ComputerName = "."
Set wmiServices = GetObject ( _
"winmgmts:{impersonationLevel=Impersonate}!//" _
& ComputerName)
' Get physical disk drive
Set wmiDiskDrives = wmiServices.ExecQuery ( _
"SELECT Caption, DeviceID, InterfaceType FROM Win32_DiskDrive")
For Each wmiDiskDrive In wmiDiskDrives
strRslt = strRslt & vbNewLine
strRslt = strRslt & vbNewLine _
& "DiskDrive.Caption = " & wmiDiskDrive.Caption _
& vbNewLine & "DiskDrive.InterfaceType = " _
& wmiDiskDrive.InterfaceType
'Use the disk drive device id to find associated partition
strQuery = "ASSOCIATORS OF {Win32_DiskDrive.DeviceID='" _
& wmiDiskDrive.DeviceID _
& "'} WHERE AssocClass = Win32_DiskDriveToDiskPartition"
Set wmiDiskPartitions = wmiServices.ExecQuery(strQuery)
For Each wmiDiskPartition In wmiDiskPartitions
'Use partition device id to find logical disk
Set wmiLogicalDisks = wmiServices.ExecQuery _
("ASSOCIATORS OF {Win32_DiskPartition.DeviceID='" _
& wmiDiskPartition.DeviceID _
& "'} WHERE AssocClass = Win32_LogicalDiskToPartition")
For Each wmiLogicalDisk In wmiLogicalDisks
strRslt = strRslt _
& vbNewLine & "DiskDrive.Caption = " _
& wmiDiskDrive.Caption _
& vbNewLine & "DiskDrive.DeviceID = " _
& wmiDiskDrive.DeviceID _
& vbNewLine & "DiskPartition.Partition = " _
& wmiDiskPartition.DeviceID _
& vbNewLine & "LogicalDisk.DeviceID = " _
& wmiLogicalDisk.DeviceID
Next
Next
Next
WScript.Echo strRslt