Sunday, April 17, 2011

Best method to obtain current memory configuration in VBA

I am attempting to get the current users RAM configuration. I would like to use VBA to look this up and then store it in a table. I need the number of chips along with the amount of RAM on each chip. Is this possible to lookup programmatically using VBA? Do I need to use Windows Script Host?

From stackoverflow
  • You can do this using 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"
    

0 comments:

Post a Comment