我可以使用哪个WMI查询来获取正在运行的httpd服务的性能信息?
hres = pSvc->ExecQuery(
bstr_t("WQL"),
bstr_t("SELECT * FROM Win32_PerfFormattedData_PerfProc_Process Where Name='httpd'"),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);
IWbemClassObject *pclsObj;
ULONG uReturn = 0;
while (pEnumerator)
{
HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1,
&pclsObj, &uReturn);
if(0 == uReturn)
{
break;
}
VARIANT vtProp;
// Get the value of the Name property
hr = pclsObj->Get(L"Name", 0, &vtProp, 0, 0);
wcout << " test : " << vtProp.bstrVal << endl;
VariantClear(&vtProp);
pclsObj->Release();
}
答案 0 :(得分:1)
只需在此代码中为Process Name添加过滤器:
strComputer ="."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery("Select * from Win32_PerfFormattedData_PerfProc_Process",,48)
wscript.echo "Computer Name" & "," & "Process Name" & ","& "CPU Usage"
For Each objItem in colProcesses
if objItem.Name <> "Idle" and objItem.Name <> "_Total" then
wscript.echo strcomputer & "," & objItem.Name & ","& objItem.PercentProcessorTime
end if
Next