Skip to content

Instantly share code, notes, and snippets.

@ayancey
Created September 15, 2016 16:59
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ayancey/fbdd982c1965698241c2e4423cc92b80 to your computer and use it in GitHub Desktop.
Save ayancey/fbdd982c1965698241c2e4423cc92b80 to your computer and use it in GitHub Desktop.
'''''''''''''''''''''''''''''
' Purpose: Allows you to easily get the RAM configuration of a computer. LAN Sweeper won't tell you the RAM type, but this utility will. This should be useful for RAM upgrades.
' Requirements: Probably admin in Active Directory
' Written by: Alex Yancey
' Date: September 15, 2016
'''''''''''''''''''''''''''''
' More info about SMBIOS can be found in the SMBIOS specification: https://www.dmtf.org/standards/smbios, and from this article: http://www.codeguru.com/cpp/misc/misc/system/article.php/c12347/SMBIOS-Demystified.htm
computer_name = InputBox("Computer name: ", "RAM Identifier")
' Get SMBIOS data using WMI
Set objWMIService = GetObject("winmgmts:\\" & computer_name & "\root\WMI")
Set smbios_array = objWMIService.ExecQuery("SELECT * FROM MSSmBios_RawSMBiosTables")
For Each i in smbios_array
Set smbios = i
Exit For
Next
smbios_string = Join(smbios.SMBiosData, ",")
''' Look for DDR, DDR2, DDR3, and DDR4 modules
ddr_modules = 0
ddr2_modules = 0
ddr3_modules = 0
ddr4_modules = 0
' The following regex objects represent the presence of type 17 objects (memory modules) in SMBIOS, with 18, 19, 24, and 26, representing DDR, DDR2, DDR3, and DDR4.
Set re_ddr = CreateObject("VBScript.RegExp")
re_ddr.Global = True
re_ddr.pattern = "17,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,18,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+"
Set re_ddr2 = CreateObject("VBScript.RegExp")
re_ddr2.Global = True
re_ddr2.pattern = "17,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,19,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+"
Set re_ddr3 = CreateObject("VBScript.RegExp")
re_ddr3.Global = True
re_ddr3.pattern = "17,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,24,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+"
Set re_ddr4 = CreateObject("VBScript.RegExp")
re_ddr4.Global = True
re_ddr4.pattern = "17,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,26,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+,\d+"
For Each i in re_ddr.Execute(smbios_string)
ddr_modules = ddr_modules + 1
Next
For Each i in re_ddr2.Execute(smbios_string)
ddr2_modules = ddr2_modules + 1
Next
For Each i in re_ddr3.Execute(smbios_string)
ddr3_modules = ddr3_modules + 1
Next
For Each i in re_ddr4.Execute(smbios_string)
ddr4_modules = ddr4_modules + 1
Next
ram_type = "Unknown"
If ddr_modules > 0 Then
ram_type = "DDR"
ElseIf ddr2_modules > 0 Then
ram_type = "DDR2"
ElseIf ddr3_modules > 0 Then
ram_type = "DDR3"
ElseIf ddr4_modules > 0 Then
ram_type = "DDR4"
End If
ram_graphic = ""
' Get total amount of RAM, accurately
Set objWMIService = GetObject("winmgmts:\\" & computer_name & "\")
Set dimms = objWMIService.ExecQuery("SELECT * FROM Win32_PhysicalMemory")
total_ram_gigs = 0
used_dimms = 0
For Each dimm in dimms
used_dimms = used_dimms + 1
total_ram_gigs = total_ram_gigs + (dimm.Capacity / 1024 / 1024 / 1024)
ram_graphic = ram_graphic + vbCrLf & (dimm.Capacity / 1024 / 1024 / 1024) & "GB " & dimm.Speed & " MHz"
Next
' Get empty DIMMS
Set pma = objWMIService.ExecQuery("Select * from Win32_PhysicalMemoryArray")
total_dimms = 0
For Each p in pma
total_dimms = p.MemoryDevices
Exit For
Next
empty_dimms = total_dimms - used_dimms
If empty_dimms = 0 Then
empty_dimms = "No"
ElseIf empty_dimms > 0 Then
For i = 1 To empty_dimms
ram_graphic = ram_graphic & vbCrLf & "EMPTY SLOT"
Next
End If
' Read out all the information
Msgbox total_ram_gigs & "GB " & ram_type & " between " & used_dimms & " slots. " & empty_dimms & " empty slots." & vbCrLf & ram_graphic, 0, "RAM info for " & computer_name
@akaleeroy
Copy link

Awesome script!
I added & dimm.Manufacturer & " " & dimm.PartNumber to ram_graphic.
And a reminder about copying the text ( & vbCrLf & "Ctrl+C to copy") to the Msgbox based on this answer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment