下面显示的基本脚本将回显它在colItems中找到的每个objItem.MemoryDevices(M)的值。但是,这不是我想要的。由于每个值总是一个数字,我希望它能回显它找到的所有值的总和。
strComputer = "."
Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" )
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PhysicalMemoryArray",,48 )
For Each objItem in colItems
M = objItem.MemoryDevices
Wscript.Echo M
Next
答案 0 :(得分:1)
VBScript将自动在字符串和数字类型之间进行转换。您应该能够通过将总计集添加到数字来完成您想要的任务,然后通过变量M增加总计。
strComputer = "."
Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" )
Set colItems = objWMIService.ExecQuery("SELECT * FROM
Win32_PhysicalMemoryArray",,48 )
Total = 0
For Each objItem in colItems
M = objItem.MemoryDevices
Total = Total + M
Next
WScript.Echo Total