0

How can I find the current pagefile size of a drive?

Priror to windows 7, There used to be a script named pafefileconfig.vba in System32 folder which can be used. But its now removed.

Is it possible to get the details using JNA? If yes, how?

EDIT

This is the code i wrote to get the pagefile info using JNA:

  Kernel32 kernel32 = (Kernel32)Native.loadLibrary("kernel32", Kernel32.class);
    MEMORYSTATUSEX memInfo = new MEMORYSTATUSEX();
    kernel32.GlobalMemoryStatusEx(memInfo);
    int toMB = (1024*1024);
    float RAM = memInfo.ullTotalPhys.floatValue();
    float totalPage = memInfo.ullTotalPageFile.floatValue();
    float availPage = memInfo.ullAvailPageFile.floatValue();
    float availRam = memInfo.ullAvailPhys.floatValue();

    System.out.println(memInfo.dwMemoryLoad);
    System.out.println("RAM "+RAM/toMB);
    System.out.println("RAM avail "+availRam/toMB);
    float ramUsed = RAM-availRam;
    System.out.println("RAM used "+ramUsed/toMB);
    System.out.println("Total page(RAM+Page) "+(totalPage)/toMB);
    float totalPageWithoutRam = totalPage-RAM;
    System.out.println("Total page(without RAM) "+(totalPageWithoutRam)/toMB);
    System.out.println("Total avail page(With free ram) "+availPage/toMB);
    float avialPageWithoutRam = availPage-availRam;
    System.out.println("Total page avail(Without ram) "+(avialPageWithoutRam)/toMB);
    System.out.println("Page used so far(Without ram) "+(totalPageWithoutRam-avialPageWithoutRam)/toMB);

And this is the output:

82
RAM 12285.582
RAM avail 2167.6758
RAM used 10117.906
Total page(RAM+Page) 24569.348
Total page(without RAM) 12283.766
Total avail page(With free ram) 12115.641
Total page avail(Without ram) 9947.965
Page used so far(Without ram) 2335.8008

I got the same result on using GetPerformanceInfo aswell.

But this looks different from what i get when i run wmic pagefile

wmic:root\cli>pagefile list /format :list


AllocatedBaseSize=12285
CurrentUsage=843
Description=C:\pagefile.sys
InstallDate=20120329043502.876449+330
Name=C:\pagefile.sys
PeakUsage=843
Status=
TempPageFile=FALSE

Why I am seeing a difference?

vishnu viswanath
  • 3,794
  • 2
  • 36
  • 47
  • Have you looked at the source of `pagefileconfig.vba` for inspiration? I'd guess(since I lack a copy) that it would contain a set of calls to libraries or executable commands that could be related to the task, though I'd assume the calls would have changed going into Windows 7. – nanofarad Oct 10 '13 at 10:33

1 Answers1

4

Well the information is exposed through WMI, you can use the wmic command line tool to list the pagefile information.

e.g. on my desktop:

C:\WINDOWS\system32>wmic pagefile list /format:list


AllocatedBaseSize=3840
CurrentUsage=213
Description=C:\pagefile.sys
InstallDate=20110616154020.168800+060
Name=C:\pagefile.sys
PeakUsage=231
Status=
TempPageFile=FALSE

You could integrate it using ProcessBuilder, etc...

As it was asked, this is exposing the Win32_PageFileUsage structure, which defines the sizes in MB.

Anya Shenanigans
  • 91,618
  • 3
  • 107
  • 122