需要帮助将WMI值转换为VBScript变量

时间:2017-09-03 22:30:09

标签: vbscript wmi

我不是程序员,但我试图通过使用VBScripts来扩展Bginfo可以从计算机收集的信息量。我有一些工作,但一些WMI查询返回多行值。我想将这些多行分开,以便我可以单独使用它们。这是我从WMIGen部分创建的一个例子:

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly       = &h20

strComputer = "."


Dim Installed
Dim Size


Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" )
Set colSlots = objWMIService.ExecQuery( "SELECT * FROM Win32_PhysicalMemoryArray", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly )
Set colMem = objWMIService.ExecQuery( "SELECT * FROM Win32_PhysicalMemory", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly )

On Error Resume Next

For Each objSlot In colSlots
    TotalSlots = objSlot.MemoryDevices
Next

For Each objMem In colMem
    MemDevices = objMem.DeviceLocator
    PartNumbers = objMem.PartNumber
    Size = Round(objMem.Capacity / 1073741824) & " GB"
Next

On Error Goto 0

MemDevices,PartNumbers和Size all为我提供了多行结果,具体取决于存储设备的数量。如何单独获取每一行的值并将其变为变量?以下是我的想法:

RAM 1: Size in GB, Part Number, slot number on board.
RAM 2: Size in GB, Part number, slot number on board
"" Continue the list for the remaining RAM sticks ""

1 个答案:

答案 0 :(得分:2)

如果需要未定义数量的相同类型的变量,可以在VBScript中使用数组变量。 对于使用Bginfo实用程序,没有必要使用该变量。 您可以生成关于循环的信息:

i = 1
For Each objMem In colMem
    MemDevices = objMem.DeviceLocator
    PartNumbers = objMem.PartNumber
    Size = Round(objMem.Capacity / 1073741824) & " GB"
    Echo "RAM " & i & " Size: " & Size & " Part Nr. " & PartNumbers
    i = i + 1
Next