我正在尝试获取当前用户的RAM配置。我想用VBA来查看它,然后将它存储在一个表中。我需要芯片的数量以及每个芯片上的RAM量。这可以使用VBA以编程方式查找吗?我需要使用Windows脚本宿主吗?
答案 0 :(得分:5)
您可以使用WMI执行此操作:
Dim devlist as object
Dim dev as object
Dim totalRAM as long
Dim numChips as long
Set devlist = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("SELECT * FROM Win32_LogicalMemoryConfiguration")
numChips = 0
For Each dev In devlist
numChips = numChips + 1
totalRAM = totalRAM + CLng(dev.TotalPhysicalMemory)
Next
devlist = Nothing
MsgBox "RAM: NumChips = " & numChips & ", Total = " & (totalRAM / 1024) & "MB"