The VBScript Network and Systems Administrator's Cafe

Mar 31 2009   1:22PM GMT

Writing a BGINFO like Script: Displaying Memory information via WMI using the Win32_PhysicalMemory class

Jerry Lees Jerry Lees Profile: Jerry Lees

I recently had to provide the information displayed with BGINFO on a number of systems. Unfortunately, BGInfo only generates a bitmap, so far as I know, so I decided to write a script to generate the information and use this displayed information to send back to the person who requested it.

The function below is a part of the script I mentioned. It retrieves and returns text that represents the total amount of physical memory in a system.

You can view all the scripts in this BGINFO series here.

Here is the code:

Function GetPhysicalMemory(strComputer)
Dim colItems, objItem, address
Dim StrQuery
Dim objWMIService, RAM
GetPhysicalMemory = VbCrLf
RAM = 0

StrQuery = “SELECT * FROM Win32_PhysicalMemory”
Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\CIMV2”)
Set colItems = objWMIService.ExecQuery(strQuery,,48)

For Each objItem in colItems
RAM = RAM + objItem.capacity
GetPhysicalMemory = GetPhysicalMemory & vbTab & (((RAM/1024)/1024)/1024) & ” Gb” & VbCrLf
End Function

1  Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.
  • stephenj
    I've copied and pasted the script above into a text file by the name of:BGINFO_Memory.vbsIn BGINFO, I add a custom field, click New, select VB Script file, and navigate to the BGINFO_Memory.vbs at the UNC path it resides at, select the file, click Open, which drops me back to the "Modify Field" dialog box.  I click on "OK" and then OK to leave the "User Defined Fields" and am presented an error of:BGinfoError evaluating scripted field 'Memory_VBS'Microsoft VBScript compilation errorLine 8, Position 11Invalid characterI attempted the same with the Network speed script and same error but it occurs on Line 6, Position 11My VBScript skills are non existent.. I copy and paste very well :)Copying the VBS script to root of C: of the Windows 2008 Server did not resolve the error, I was also able to recreate the error on Windows 7, x64Any help on resolving this issue would be greatly appreciated.thanks,Stephen
    0 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: