How to find out how many slots / memory banks are being used in VB

I am developing a project in Visual Basic and would like to know how I can read the amount of slots / banks of RAM memory there is in use on the computer, also the value of RAM memory installed in each slot / bank in use, and the total RAM memory.

Author: It Wasn't Me, 2019-05-31

1 answers


insert the description of the image here


Welcome to SO / en

You can get the information using the WMI in your vbs:


strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_PhysicalMemory",,48)
Total_size = 0 
For Each objItem in colItems
    size = FormatNumber(objItem.Capacity/1024^3, 0)
    Wscript.Echo "Slot: " + objItem.BankLabel + vbNewLine + "Capacidade: " & size & "GB" & vbNewLine +  "Obs.: " + objItem.Tag
    Total_size= (Total_size + size)
Next
Wscript.Echo "Total de Ram: " & Total_size & "GB"

Or with a slot counter in use:


insert the description of the image here


strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_PhysicalMemory",,48)
Total_Size = 0 
Total_Slot = 0
For Each objItem in colItems
    Size = FormatNumber(objItem.Capacity/1024^3, 0)
    If Size <> 0 Then
    Wscript.Echo "Slot: " + objItem.BankLabel + vbNewLine + "Capacidade: " & Size & "GB" & vbNewLine +  "Obs.: " + objItem.Tag
    Total_Size= (Total_Size + Size)
    Total_Slot= Total_Slot + 1
    End If
Next
Wscript.Echo "Slots em uso: " & Total_Slot & vbNewLine & "Total de Ram: " & Total_size & "GB"



 3
Author: It Wasn't Me, 2019-06-03 15:39:10