2010-12-09 81 views
3

我已經使用WMI來檢測操作系統上是否存在防病毒軟件, itz woking fine and display me information使用命名空間:\ root \ SecurityCenter和\ root \ SecurityCenter,\ root \ Security來獲取win xp和window7上的防病毒名稱和實例ID。如何使用WMI或其他WMI在C++中檢測安裝在Windows 2003 Server和2008 server 2003服務器R2和2008服務器R2上的防病毒

if(isHLOSVersion()) 

hres = pLoc->ConnectServer(_bstr_t(L"root\\SecurityCenter2"), 
// Object path of SecurityCenter 

NULL,     // User name. NULL = current user 

     NULL,     // User password. NULL = current 

     0,      // Locale. NULL indicates current 

     NULL,     // Security flags. 

     0,      // Authority (e.g. Kerberos) 

     0,      // Context object 

     &pSvc     // pointer to IWbemServices proxy 

     ); 
else 
    hres = pLoc->ConnectServer(_bstr_t(L"root\\SecurityCenter"), 
// Object path of SecurityCenter 

    NULL,     // User name. NULL = current user 

     NULL,     // User password. NULL = current 

     0,      // Locale. NULL indicates current 

     NULL,     // Security flags. 

     0,      // Authority (e.g. Kerberos) 

     0,      // Context object 

     &pSvc     // pointer to IWbemServices proxy 

     ); 

但在Windows的情況下,2003服務器和2008服務器2003服務器中R 2 2008服務器R2以上這些命名空間中不存在那麼這是不是在那裏工作。

請讓我知道我們如何檢測到防病毒存在或不存在Windows 2003 Server和2008 server 2003 server R2和2008 server R2操作系統。

+0

請在輸入代碼樣本時使用代碼標籤,沒有人會嘗試讀取它當前的狀態。 – 2010-12-09 09:47:28

回答

2

該命名空間在Windows Server平臺上不可用,我認爲它可能會被棄用於Workstation(即將離開)。

您可以使用WscGetSecurityProviderHealth()獲得相同的結果。

http://msdn.microsoft.com/en-us/library/bb432506.aspx

這裏是我的,似乎工作瑣碎樣本:

#define _WIN32_WINNT _WIN32_WINNT_WIN7 
#include <Windows.h> 
#include <Wscapi.h> 
#include <iostream> 

#pragma comment(lib, "Wscapi") 


int main(int argc, char* argv[]) 
{ 
    WSC_SECURITY_PROVIDER_HEALTH health; 
    const DWORD dwAntivirus(WSC_SECURITY_PROVIDER_ANTIVIRUS); 

    HRESULT hr = WscGetSecurityProviderHealth(dwAntivirus, &health); 
    if (FAILED(hr)) 
    { 
     std::cerr << "Error " << std::hex 
       << std::showbase << hr << "\n"; 
     return -1; 
    } 
    switch (health) 
    { 
     case WSC_SECURITY_PROVIDER_HEALTH_GOOD: 
     std::cout << "Antivirus health is good\n"; 
     return 0; 
     case WSC_SECURITY_PROVIDER_HEALTH_NOTMONITORED: 
     std::cout << "Antivirus health is not monitored\n"; 
     return 1; 
     case WSC_SECURITY_PROVIDER_HEALTH_POOR: 
     std::cout << "Antivirus health is poor\n"; 
     return 2; 
     case WSC_SECURITY_PROVIDER_HEALTH_SNOOZE: 
     std::cout << "Antivirus health is snooze\n"; 
     return 3; 
     default: 
     std::cout << "Unexpected antivirus health value: " 
        << std::hex << std::showbase 
        << health << "\n"; 
     return 4; 
    } 
} 

更新2012年12月9日

亞歷克斯指出(見下文),這並不在Windows Server上運行僅在Windows的Workstation版本上。經過反思,我發現它可能是故意的,實際上可能是最好的。

應用程序真的需要知道服務器的狀態嗎?大多數服務器安全程序都有機制在失敗時設置警報。管理員將監視這些警報並修復損壞的內容。應用程序應該簡單地表現爲安全性完全可操作。

如果你真的需要瞭解某個特定的程序,你可以在進程中查找它的exe名稱,看看該進程是否正在運行並且正在使用cpu(未掛起)。除此之外,您可能需要與安全程序的供應商合作:他們可能有API來查詢程序。

+0

根據您發佈的文章,該功能僅適用於桌面應用程序,並且在服務器上不受支持。 – athom 2012-12-07 15:28:08

相關問題