c# - 在 C# 中检查反病毒状态

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

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

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

我使用 WMI 进行了简要浏览,但在 2008/win7 计算机上,Microsoft 已经更改了他们返回给您的信息。

总而言之,我需要以下内容:

  • 视频名称
  • 影音版
  • AV 最新
  • AV 启用/运行

有人能帮忙吗?

最佳答案

可以找到 sample here如您所述使用 WMI。海报说这是在 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"]);
    }
}

关于c# - 在 C# 中检查反病毒状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4750507/

相关文章:

windows - 请求的 IIS 文件授权失败

c# - 使用 SQL Server 存储数据

c# - 在迭代器的 finally block 中获取对异常的引用

c# - 在没有类型先验知识的情况下在 C# 中解码 JSON 对象

c# - 聚合 IEnumerable 中的一系列连续 block

powershell - 远程 PowerShell 脚本不应用 Hyper-V 快照

asp-classic - 如何从 Windows 2008 Server 上的 ASP 应用程序发送电子邮件

php - 在 Windows Server 2003 上安装 PHP 5 - %1 不是有效的 Win32 应用程序

asp.net-mvc-3 - 为什么/eurl.axd/Gibberish 被添加到我的页面末尾?

windows - 域帐户每隔几分钟就会用正确的密码锁定一次