tags:

views:

23

answers:

2

Windows XP/Vista/7

  1. System Properties
  2. Advanced tab
  3. Settings... button under Performance
  4. Advanced tab
  5. Change... button
  6. The numbers at the bottom of that window in the "Total paging file size for all drives" section

Anybody know how I would go about getting those three numbers from within a C++ program?

Thanks!

+1  A: 

You can do some of this using WMI, the class you want is Win32_PageFileSetting. In .Net this is (more easily) accessed via System.Management. If you want runtime usage, you can use Win32_PageFileUsage.

Note the elevated privilege you require in that documentation.

I don't see any way to access the minimum and recommended values, at this point.

Steve Townsend
WMI is an awfully complicated way to get this information.
Billy ONeal
@Billy - WMI is still afaik Microsoft's preferred solution for system management. Don't shoot the messenger please. Your alternative looks good but registry modification has its own pitfalls.
Steve Townsend
@Steve: Not shooting the messenger. Just saying :) Getting at WMI data in C++ is just a big freaking cluster f*** :(. +1.
Billy ONeal
@Billy - no argument, C# makes this a lot easier.
Steve Townsend
+1  A: 

That information is stored in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Session Manager\Memory Managment in the PagingFiles value. It is a REG_MULTI_SZ, and each string is of the form:

PAGINGFILEPATH StartSize MaxSize

So, for example, I set my C drive to be 16384 MB for both sizes, the key data would look like:

L"C:\pagefile.sys 16384 16384\0"

NOTE2: It's possible to omit the numbers, in which case the system manages the size of the page file on the specified drive.

NOTE: The value specified there is not the value the system is currently using, but the value that will be used upon system reboot. This is because the paging file generally cannot be changed once the system is running, except to expand the paging file. So if the user would have changed the setting but not rebooted, that key would contain the settings for after reboot, not the settings currently in effect.

If you want the settings currently in effect you can check the sizes of pagefile.sys on each of the drives. That won't give you the max size but it will at least give you an idea.

Billy ONeal
+1, this is programmatically the easiest in C++
Steve Townsend
@Steve: Thank you. +1 to you too :)
Billy ONeal
Sadly that doesn't work if Virtual Memory is set to "System managed size". It only works if you've specified the entries manually. Otherwise the registry entry just has the filename.(At least that's true on Vista, not sure about XP/7 at the moment)
Drew Roberts
@Drew: "System Managed Size" is just that -- it's not set anywhere, and the Kernel chooses a size it thinks appropriate for the given workload. If there are no sizes, then you can just assume system managed size, and there's nothing more you can say about the pagefile configuration. How the kernel chooses which size to use isn't defined anywhere I can find.
Billy ONeal