用于确定服务是否正在执行其工作的 WMI 查询
我设法使用 WMI 查询 httpd.exe 服务以检查它是正在运行还是已停止。这是我正在使用的代码:
hres = pSvc->ExecQuery(
bstr_t("WQL"),
bstr_t("SELECT * FROM Win32_Process Where Name='httpd.exe'"),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);
现在我想查询该服务正在使用的 CPU 量。我想知道正在运行的服务是否正在工作。这可以做到吗?我问的问题正确吗?需要建议:)
I managed to query the httpd.exe service using WMI to check whether it is running or stopped. Here is the code that I am playing with:
hres = pSvc->ExecQuery(
bstr_t("WQL"),
bstr_t("SELECT * FROM Win32_Process Where Name='httpd.exe'"),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);
Now I would like to query the amount of CPU that the service is using. I want to know whether the running service is doing work or not. Can this be done? Am I asking the right question? need advice :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
Win32_Process
,您可以获得UserModeTime
和KernelModeTime
(以100纳秒为单位),这允许您计算期间每个CPU的平均值某个时间。假设您获得两个由
TimeInterval
(以 100 纳秒单位给出)分隔的Win32_Process
信息。如果您想要从一开始的速率,您可以计算从
CreationDate
到现在的TimeInterval
。Using
Win32_Process
, You are able to get theUserModeTime
and theKernelModeTime
(given in 100 nanosecond units) which allows you to compute each CPU average during a certain time.Assuming you get two
Win32_Process
informations separate by aTimeInterval
(given in 100 nanosecond units).If you want the rate from the begining, you can compute
TimeInterval
fromCreationDate
to now.