Win32_LogicalMemoryConfiguration在win7下无法使用

strComputer = "."

Set objSWbemServices = GetObject("winmgmts:\" & strComputer)
Set colSWbemObjectSet = _
objSWbemServices.InstancesOf("Win32_LogicalMemoryConfiguration")

For Each objSWbemObject In colSWbemObjectSet
Wscript.Echo "Total Physical Memory (kb): " & _
objSWbemObject.TotalPhysicalMemory
Next
这段代码在win7下无法运行报错(null): 0x80041010 在win2003下可以运行,win7下已经取消Win32LogicalMemoryConfiguration类
以下是替代方法
strComputer = "."
Set objWMIService = GetObject("winmgmts:\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery(

"SELECT * FROM Win32_PhysicalMemory",,48)
For Each objItem in colItems
Wscript.Echo "-----------------------------------"
Wscript.Echo "Win32_PhysicalMemory instance"
Wscript.Echo "-----------------------------------"
Wscript.Echo "Capacity: " & objItem.Capacity
Next
用Win32_PhysicalMemory instance代替之

猜你喜欢

转载自blog.51cto.com/4432704/2342798