My goal is to detect the total amount of physical memory in the system regardless of any value set via /maxmem in boot.ini. The principle behind this technique is that if maxmem is set in boot.ini, and the value it is set to is less than what the system actually reports, then the system's memory is being artificially crippled. I don't need help parsing boot.ini or comparing, just where to look to get the hardware-level memory size.
I am working in (Visual Studio 2005) C++ in the Win32 environment. My target platform is Windows XP Service Pack 2. I actually have a solution in C# using .NET, but this does not work since .NET is unlikely to be pre-Installed on machines the program is used on.
The following is a C# snippet which doesn't seem to be restricted by /maxmem.
Expand|Select|Wrap|Line Numbers
- ManagementObjectSearcher searcher =
- new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMemory");
- foreach (ManagementObject bank in searcher.Get()) {
- MessageBox.Show(" size = " + bank["Capacity"].ToString());
- }
I've tried GetMemoryStatusEx; unfortunately what it returns for "total memory" is still restricted by maxmem. If I find a solution before anyone responds I'll post back.