How to List Memory Devices in VBScript?


The WMI Service object on windows is very powerful, it allows us to list memory devices easily by retrieving information via query, which looks like SQL. The query to list memory devices is:

Select * from Win32_MemoryDevice

With VBScript, the code snippet is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
' List Memory Devices
On Error Resume Next
 
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
 
Set colItems = objWMIService.ExecQuery("Select * from Win32_MemoryDevice")
 
For Each objItem in colItems
    Wscript.Echo "Device ID: " & objItem.DeviceID
    Wscript.Echo "Ending Address: " & objItem.EndingAddress
    Wscript.Echo "Starting Address: " & objItem.StartingAddress
    Wscript.Echo
Next
' List Memory Devices
On Error Resume Next

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * from Win32_MemoryDevice")

For Each objItem in colItems
    Wscript.Echo "Device ID: " & objItem.DeviceID
    Wscript.Echo "Ending Address: " & objItem.EndingAddress
    Wscript.Echo "Starting Address: " & objItem.StartingAddress
    Wscript.Echo
Next

On my Lenovo M900 Workstation, the results are (32GB RAM).

Device ID: Memory Device 0
Ending Address: 8388607
Starting Address: 0

Device ID: Memory Device 1
Ending Address: 25165823
Starting Address: 16777216

Device ID: Memory Device 2
Ending Address: 16777215
Starting Address: 8388608

Device ID: Memory Device 3
Ending Address: 33554431
Starting Address: 25165824

Of course, you can also do the same in Microsoft JScript (as long as it runs under Windows Scripting Host) or other scripting languages.

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
254 words
Last Post: How to List Installed Hot Fixes using VBScript on Windows Platforms?
Next Post: How to List Keyboard Properties using VBScript and WMI Object?

The Permanent URL is: How to List Memory Devices in VBScript?

Leave a Reply