Win32_PageFileUsage WMI call returning 0 for CurrentUsage
I am querying for the current page file usage on Windows-based systems. This is meant to run on the .NET Framework, version 2.0 SP1 and has been tested (and works!) on Windows Vista, Windows 7, Windows Server 2003 R2 and Windows Server 2008.
On Windows Server 2003 SP2 (original release, not R2) it appears to return 0:
using (var query = new ManagementObjectSearcher("SELECT CurrentUsage FROM Win32_PageFileUsage"))
{
foreach (ManagementBaseObject obj in query.Get())
{
uint used = (uint)obj.GetPropertyValue("CurrentUsage");
return used;
开发者_StackOverflow社区 }
}
This is simply returning the results from the first row returned for the WMI call. Even when a page file is being used, it returns 0. What causes the result to be 0 when it should be returning a larger value?
It may be something specific to the machine in question, and could have nothing to do with the operating system version. I've also tried this with and without elevated privileges with the same results.
The WMI provider is probably reading the same stat data store used by the \PagingFile\% Usage counter.
Try use PdhOpenQuery/PdhAddCounter/PdhCollectQueryData instead.
It turns out the value actually was zero. The hosting provider in this particular instance set all paging memory to 0 MB. So, the data being returned via WMI was indeed correct.
精彩评论