Tripredacus Posted August 14, 2012 Posted August 14, 2012 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 Properties2 - 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 = 2613805056Win32_OperatingSystem: TotalVisibleMemorySize = 2552544Win32_PhysicalMemory: Capacity = 2147483648Win32_PhysicalMemory: Round(Capacity / (1024^2)) = 2048The 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?
submix8c Posted August 14, 2012 Posted August 14, 2012 Hmmm... dividing the last value given by 1024 yields a "slightly rounded down" 4096 (4gib)....and thanks for the REG entries.
Tripredacus Posted August 14, 2012 Author Posted August 14, 2012 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.
submix8c Posted August 14, 2012 Posted August 14, 2012 Been a real bad year/decade... a wonder my brain thinks of Captain Obvious items anymore. Glad to assist... and again - thanks!
gunsmokingman Posted August 14, 2012 Posted August 14, 2012 You could of just used the WMI ComputerSystem to get the amount of installed ram.Example WMI ComputerSystem ClassConst GB = 1073741824Const MB = 1048576Dim Obj, WmiSet 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
Tripredacus Posted August 15, 2012 Author Posted August 15, 2012 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.
gunsmokingman Posted August 15, 2012 Posted August 15, 2012 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.
Tripredacus Posted August 15, 2012 Author Posted August 15, 2012 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 GBWin32_ComputerSystem: TotalPhysicalMemory = 2613805056 / 1048576 = 2492.71875 MBTask Manager values for Physical Memory (MB)Total: 2492It 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.
gunsmokingman Posted August 15, 2012 Posted August 15, 2012 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.
Drugwash Posted April 24, 2013 Posted April 24, 2013 (edited) 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(added screenshot) Edited April 24, 2013 by Drugwash
Yzöwl Posted April 24, 2013 Posted April 24, 2013 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 PromptWMIC MEMORYCHIP GET capacity, devicelocatorPowershell PromptGet-WmiObject CIM_PhysicalMemory | select capacity,devicelocator | ft -AutoSize
Drugwash Posted April 24, 2013 Posted April 24, 2013 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.
gunsmokingman Posted April 24, 2013 Posted April 24, 2013 I made a VB Net app that show ram usage and basic OS information.This is from this ThreadGet_KeyV1.exe
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now