我使用WMI检测操作系统上是否存在防病毒, itz woking很好,并使用命名空间:\ root \ SecurityCenter和\ root \ SecurityCenter,\ root \ Security。在win xp和window7上显示防病毒信息,如名称和实例ID。
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服务器R2和2008服务器R2,这些上面的命名空间不存在,所以这不起作用。
请告诉我们如何检测防病毒是否存在Windows 2003服务器和2008 Server 2003服务器R2和2008服务器R2操作系统。
答案 0 :(得分: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日更新
Alex指出(下面)这不适用于Windows Server,仅适用于Windows的Workstation版本。经过反思,我发现它可能是故意的,实际上可能是最好的。
应用程序真的需要知道服务器的状态吗?大多数服务器安全程序都有机制在失败时设置警报。管理员将监视这些警报并修复损坏的内容。应用程序应该只是表现为安全性完全正常运行。
如果您确实必须了解特定程序,您可以在进程中查找其exe名称,并查看进程是否正在运行并且正在使用cpu(未挂起)。除此之外,您可能需要与安全程序的供应商合作:他们可能有一个API来查询程序。