MSFN Forum: Find actual total physical memory - MSFN Forum

Jump to content


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Find actual total physical memory WMI or registry? Rate Topic: -----

#1 User is offline   Tripredacus 

  • K-Mart-ian Legend
  • Group: Super Moderator
  • Posts: 8,665
  • Joined: 28-April 06
  • OS:Server 2012
  • Country: Country Flag

Posted 14 August 2012 - 10:44 AM

I'm writing a new program that needs to read how much RAM is on a PC, and then create a disk partition that matches that size. The problem I am encountering is that I cannot find exactly the correct class in WMI that has this information. Using my own PC as an example, I have 2 different memory amounts.

1 - 4.00 GB is reported as "Installed memory" on Computer Properties
2 - 2.43 GB usable in the same place, also matches Task Manager's Performance tab of 2492 Total Physical Memory.

I want to get this 4GB value that I see in Computer Properties, but all I can find is the lower number. Examples:

Win32_ComputerSystem: TotalPhysicalMemory = 2613805056
Win32_OperatingSystem: TotalVisibleMemorySize = 2552544
Win32_PhysicalMemory: Capacity = 2147483648
Win32_PhysicalMemory: Round(Capacity / (1024^2)) = 2048

The only thing close I can find is Win32_MemoryArray (or MemoryDevice): EndingAddress = 4194303.
That is presuming that number is showing me the RAM address. I tested on a 1GB system and it returns a 1xxxxxx value.

So where can I get the Installed Memory size data from?


#2 User is offline   submix8c 

  • Inconceivable!
  • Group: Patrons
  • Posts: 3,241
  • Joined: 14-September 05
  • OS:none specified
  • Country: Country Flag

Posted 14 August 2012 - 11:11 AM

Hmmm... dividing the last value given by 1024 yields a "slightly rounded down" 4096 (4gib).

...and thanks for the REG entries.

#3 User is offline   Tripredacus 

  • K-Mart-ian Legend
  • Group: Super Moderator
  • Posts: 8,665
  • Joined: 28-April 06
  • OS:Server 2012
  • Country: Country Flag

Posted 14 August 2012 - 11:28 AM

Hmm why didn't I think of that? Using Win32_MemoryArray ...

Round ( EndingAddress / (1024^2))


Gives me "4" on a 4GB PC and "8" on an 8GB PC. This might just be the thing to use.

#4 User is offline   submix8c 

  • Inconceivable!
  • Group: Patrons
  • Posts: 3,241
  • Joined: 14-September 05
  • OS:none specified
  • Country: Country Flag

Posted 14 August 2012 - 11:54 AM

:w00t: Been a real bad year/decade... a wonder my brain thinks of Captain Obvious items anymore. :wacko:

Glad to assist... and again - thanks!

#5 User is offline   gunsmokingman 

  • MSFN Master
  • Group: Super Moderator
  • Posts: 2,351
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 14 August 2012 - 12:37 PM

You could of just used the WMI ComputerSystem to get the amount of installed ram.
Example WMI ComputerSystem Class
Const GB = 1073741824
Const MB = 1048576
Dim Obj, Wmi
Set Wmi = GetObject("winmgmts:\\.\root\CIMV2") 
For Each Obj In Wmi.ExecQuery("SELECT * FROM Win32_ComputerSystem") 
 If Obj.TotalPhysicalMemory > Int(GB) Then
  msgbox _
  "Total Physical Memory : " & FormatNumber(Obj.TotalPhysicalMemory / GB,2) & " GB"
 Else
  msgbox _
  "Total Physical Memory : " & FormatNumber(Obj.TotalPhysicalMemory / MB,2) & " MB"
 End If 
Nex



#6 User is offline   Tripredacus 

  • K-Mart-ian Legend
  • Group: Super Moderator
  • Posts: 8,665
  • Joined: 28-April 06
  • OS:Server 2012
  • Country: Country Flag

Posted 15 August 2012 - 08:43 AM

I tried that one and did not get the actual physical memory, but what Windows saw as the total after ignoring the 32bit limitation, and whatever (must be) allocated to video.

#7 User is offline   gunsmokingman 

  • MSFN Master
  • Group: Super Moderator
  • Posts: 2,351
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 15 August 2012 - 12:43 PM

This is what I get on my 64 bit Win 7

Quote

---------------------------

---------------------------
Total Physical Memory : 8.00 GB
---------------------------
OK
---------------------------

So it says I have 8 gigs of ram installed, the exact amount I have on my machine. 4 x 2 GB Ram sticks installed on my machine.

Quote

I tried that one and did not get the actual physical memory, but what Windows saw as the total after ignoring the 32bit limitation, and whatever (must be) allocated to video.

So what your saying
Example
I have a video card that uses 1 GIG of ram and I have 8 gigs you expect this WMI Class to subtract 1 GIG of ram and say you have only 7 gigs.
That would give a incorrect amount of installed ram 7 GIGS.


The question ask was TOTAL INSTALL RAM not figure out ram after video card usage, usable ram on a 32 bit OS. This WMI Class give
what ever amount of working RAM sticks that are plug into the RAM Slots.

#8 User is offline   Tripredacus 

  • K-Mart-ian Legend
  • Group: Super Moderator
  • Posts: 8,665
  • Joined: 28-April 06
  • OS:Server 2012
  • Country: Country Flag

Posted 15 August 2012 - 01:02 PM

For this PC that I am working on, has 4GB (4x1GB DDR2) in it, I get these values:

Win32_ComputerSystem: TotalPhysicalMemory = 2613805056 / 1073741824 = 2.434295654296875 GB
Win32_ComputerSystem: TotalPhysicalMemory = 2613805056 / 1048576 = 2492.71875 MB

Task Manager values for Physical Memory (MB)
Total: 2492

It is only a guess for me that my missing ~708MB RAM (3.200GB - 2.492GB) is due to the video card.

I do not know why your WMI query works for you but mine does not. :unsure:

#9 User is offline   gunsmokingman 

  • MSFN Master
  • Group: Super Moderator
  • Posts: 2,351
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 15 August 2012 - 04:42 PM

The last time I tried a 32 Bit OS on this computer, I thought I would of had 4 GB on the OS but I only
had approx 3.25 GB of 8 GB usable ram. Maybe the Wmi is reading what is left over as the amount
of Ram minus the Video Card Usage.

#10 User is offline   Drugwash 

  • MSFN Expert
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 1,097
  • Joined: 21-June 06
  • OS:98SE
  • Country: Country Flag

Posted 24 April 2013 - 07:17 AM

There's a Windows API to retrieve RAM information.
GlobalMemoryStatus() works on any 32-bit Windows. It can show a maximum of 4GB.
GlobalMemoryStatusEx() works on XP and later, both 32-bit and 64-bit.
More info at MSDN.

Here's a small utility developed by myself in AutoHotkey, that shows amount of RAM, swap file and total load, using GlobalMemoryStatus() :
MemPanel 1.0.1.0

Posted Image

(added screenshot)


This post has been edited by Drugwash: 24 April 2013 - 11:19 AM


#11 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,363
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 24 April 2013 - 10:18 AM

Two sequential calls to GlobalMemoryStatus are not guaranteed to return the same information, it is recommended to use GlobalMemoryStatusEx instead.

If you wanted to know the installed memory then perhaps using GetPhysicallyInstalledSystemMemory, (Win Vista+) will do what you want.

For simple scripting the following should show you what's installed in your RAM slots:
Command Prompt
WMIC MEMORYCHIP GET capacity, devicelocator
Powershell Prompt
Get-WmiObject CIM_PhysicalMemory | select capacity,devicelocator | ft -AutoSize


#12 User is offline   Drugwash 

  • MSFN Expert
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 1,097
  • Joined: 21-June 06
  • OS:98SE
  • Country: Country Flag

Posted 24 April 2013 - 11:06 AM

View PostYzöwl, on 24 April 2013 - 10:18 AM, said:

Two sequential calls to GlobalMemoryStatus are not guaranteed to return the same information, it is recommended to use GlobalMemoryStatusEx instead.

Relevant info is retrieved from a struct and yes, some values in certain fields will differ, such as free memory, system load, etc. But the amount of physically installed memory should have no reason to differ between calls, unless there's a bug in the API and even that might exist or not according to the OS version running.

I've developed the above application under and mainly for 98SE, therefore I had to use the simple version of the API, not the extended one. For any 32-bit Windows it should work fine. Of course, 64-bit Windows that can accept more than 4GB of RAM should use the extended version of the API instead, for an accurate result.

I could build a x64-compatible version of the application but I have no x64 system to test it on.

#13 User is offline   gunsmokingman 

  • MSFN Master
  • Group: Super Moderator
  • Posts: 2,351
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 24 April 2013 - 11:39 AM

I made a VB Net app that show ram usage and basic OS information.
Attached File  GsmBasicInfo.png (34K)
Number of downloads: 3

This is from this Thread

Get_KeyV1.exe

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2013 msfn.org
Privacy Policy