2011-03-15 44 views
0

可以使用哪個WMI查詢來獲取正在運行的httpd服務的性能信息?用於獲取正在運行的服務器的性能的WMI查詢

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

我應該按順序使用哪個屬性來知道我的服務的性能? – karikari 2011-03-15 08:48:31

回答

1

只需添加的進程名稱過濾器在這個代碼:

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 
+0

更新了我的問題。我當前的代碼只顯示服務:( – karikari 2011-03-15 08:18:46

+0

哪裏++ – karikari 2011-03-22 01:30:15

+0

硫雜文章添加該代碼在VC的名字爲例:http://www.codeproject.com/KB/system/UsingWMI.aspx – 2011-03-22 03:19:27