Win32_PageFileUsage WMI 调用为 CurrentUsage 返回 0
我正在查询基于 Windows 的系统上当前页面文件的使用情况。它旨在在 .NET Framework 版本 2.0 SP1 上运行,并已在 Windows Vista、Windows 7、Windows Server 2003 R2 和 Windows Server 2008 上进行了测试(并且有效!)。
在 Windows Server 2003 SP2(原始版本,而不是 R2)上)它似乎返回 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;
}
}
这只是返回 WMI 调用返回的第一行的结果。即使正在使用页面文件,它也会返回 0。是什么导致它应该返回更大的值时结果却是 0?
它可能是特定于有问题的机器的,并且可能与操作系统版本无关。我也尝试过使用和不使用提升的权限,得到了相同的结果。
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;
}
}
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
WMI 提供程序可能正在读取 \PagingFile\% 使用情况 计数器使用的相同统计数据存储。
尝试改用 PdhOpenQuery/PdhAddCounter/PdhCollectQueryData。
The WMI provider is probably reading the same stat data store used by the \PagingFile\% Usage counter.
Try use PdhOpenQuery/PdhAddCounter/PdhCollectQueryData instead.
事实证明该值实际上为零。此特定实例中的托管提供商将所有分页内存设置为 0 MB。因此,通过 WMI 返回的数据确实是正确的。
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.