Get the pagefile size of a drive

痞子三分冷 提交于 2020-01-06 14:55:51

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/19293297/get-the-pagefile-size-of-a-drive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!