Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WMI & Win32_LogicalMemoryConfiguration results

Status
Not open for further replies.

brianashman

Technical User
Dec 11, 2003
15
US
On the W2K Scripting Guide at


in listing 6.1 there is a script example for displaying the amount of memory installed in a machine. The results given are in KB. When divided by 1024 to get MB, the answer is not an integer.

I have also found this to be the case on my own machines with XP (SP1) & W2K (SP2). My XP machine has 1280MB, but reports 1309772KB instead of 1310720KB.

What is the cause?

What would be the best way to find the true amount of memory installed?
 
On Error Resume Next

Set oShell = CreateObject("wscript.Shell")
Set env = oShell.environment("Process")
strComputer = env.Item("Computername")

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colSettings = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
report = "******************************************" & vbCrLf
report = report & "Memory Information" & vbCrLf & "******************************************" & vbCrLf & vbCrLf
For Each objComputer in colSettings
'report = report & objComputer.Name & vbcrlf
report = report & objComputer.TotalPhysicalMemory /1024\1024+1 & "MB Total memory" & vbcrlf
Next

WScript.Echo (Report)

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
I have found a better way that gives the EXACT memeory amount:

Set WMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
set Results=WMI.ExecQuery("select * from win32_PhysicalMemory")

RAM=0
For Each Memory In Results
RAM=RAM+Memory.Capacity/1024/1024
Next
 
Brian, I hate to burst your bubble but your script doesn't work.

I have a total of 512 MB and your script only reports 256.

My guess is that if you have more than one memory card your script does not pick it up. I know I have two 256MB SDRAM cards.

My script correctly reports the 512.

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Hello all,

Cannot confirm all the claims made.

regards - tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top