Chris
Chris

Reputation: 261

Need help converting WMI values to VBScript variables

I am not a programmer, but I am trying to extend the amount of information that Bginfo can collect from a computer by using VBScripts. I've got some of it working, but some WMI queries return multiple lines of values. I'd like to split these multiple lines up so I can use them separately. Here's an example that I partially created from 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, and Size all gives me multiple lines of results depending on how many memory devices there are. How can I get the value for for each line individually and make them into variables? Here is what I was thinking about for how it would look:

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 ""

Upvotes: 0

Views: 388

Answers (1)

JoSerra
JoSerra

Reputation: 361

If you need an undefined number of variables of same type you could use an array variable in VBScript. For using with Bginfo utility is not necessary that variable. You can generate information on loop:

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

Upvotes: 2

Related Questions