Welcome to MSFN

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more! This message will be removed once you have signed in.


Tripredacus

Find actual total physical memory

13 posts in this topic

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?

0

Share this post


Link to post
Share on other sites

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

...and thanks for the REG entries.

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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

Glad to assist... and again - thanks!

0

Share this post


Link to post
Share on other sites

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

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

This is what I get on my 64 bit Win 7

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

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

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.

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.

0

Share this post


Link to post
Share on other sites

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:

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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

mempanel1010.png

(added screenshot)

Edited by Drugwash
0

Share this post


Link to post
Share on other sites

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

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.