【问题标题】:Check anti-virus status in C#在 C# 中检查防病毒状态
【发布时间】:2011-06-12 15:19:54
【问题描述】:

我需要检查一组服务器以查看防病毒软件是否是最新的并正在运行。棘手的是它们分布在 Windows 2003 和 2008 服务器上,我需要能够检查它们。

有没有办法用 C# 或 VB.NET 做到这一点?

我使用 WMI 进行了短暂的查看,但它出现在 2008/win7 计算机上,Microsoft 更改了它们返回给您的信息。

总的来说,我需要以下内容:

  • AV 名称
  • AV版
  • AV 最新版
  • AV 已启用/正在运行

谁能帮忙?

【问题讨论】:

    标签: c# windows-server-2008 windows-server-2003 antivirus


    【解决方案1】:

    根据您的环境设置方式,您可能需要指定安全性和权限。您还应注意某些防病毒产品(如 McAfee)不会通过 WMI 提供数据

    您可以使用这个 sn-p 从 WMI 查询防病毒信息:

    string computer = Environment.MachineName;  
    string wmipath = @"\\" + computer + @"\root\SecurityCenter";  
    string query = @"SELECT * FROM AntivirusProduct";
    
    ManagementObjectSearcher searcher = new ManagementObjectSearcher(wmipath, query);  
    ManagementObjectCollection results = searcher.Get();
    
    foreach (ManagementObject result in results)  
    {  
        // do something with `result[value]`);
    }
    

    【讨论】:

    • 我想知道 WHS 如何获取客户端计算机上的信息以了解您是否安装了 AV...因为 McAfee 就是其中之一;可能是我收集的特定供应商。
    • @Arron 我对检测的工作原理非常模糊,但我记得它与 McAfee eOrchestrator crud 有关。
    • 感谢格雷格的回答。似乎可以在 xp/vista (pre-sp1) 和 nt 2003 上工作。现在正在进行更多测试。
    • 抱歉忘记在服务器平台 (2003-2008) 上添加,因为它们没有要检查的命名空间
    【解决方案2】:

    可以使用您提到的 WMI 找到示例here。海报指出这是在 Win 7 机器上完成的;所以下面的代码应该让你开始......

    ConnectionOptions _connectionOptions = new ConnectionOptions();
    //Not required while checking it in local machine.
    //For remote machines you need to provide the credentials
    //options.Username = "";
    //options.Password = "";
    _connectionOptions.EnablePrivileges = true;
    _connectionOptions.Impersonation = ImpersonationLevel.Impersonate;
    //Connecting to SecurityCenter2 node for querying security details
    ManagementScope _managementScope = new ManagementScope(string.Format("\\\\{0}\\root\\SecurityCenter2", ipAddress), _connectionOptions);
    _managementScope.Connect();
    //Querying
    ObjectQuery _objectQuery = new ObjectQuery("SELECT * FROM AntivirusProduct");
    ManagementObjectSearcher _managementObjectSearcher =
        new ManagementObjectSearcher(_managementScope, _objectQuery);
    ManagementObjectCollection _managementObjectCollection = _managementObjectSearcher.Get();
    if (_managementObjectCollection.Count > 0)
    {
        foreach (ManagementObject item in _managementObjectCollection)
        {
            Console.WriteLine(item["displayName"]);
            //For Kaspersky AntiVirus, I am getting a null reference here.
            //Console.WriteLine(item["productUptoDate"]);
    
            //If the value of ProductState is 266240 or 262144, its an updated one.
            Console.WriteLine(item["productState"]);
        }
    }
    

    【讨论】:

    • 谢谢。这是我最初感到困惑的 productState。这个答案让我找到了:neophob.com/2010/03/wmi-query-windows-securitycenter2,这有助于了解有关产品状态的更多信息。还发现securityCenter2显然是Vista SP1+。
    • 一个问题,我们可以在 Windows 7 中获得最新的防病毒功能吗? @Aaron McIver
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-26
    • 1970-01-01
    • 1970-01-01
    • 2010-10-13
    • 2011-03-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多