我需要检查一组服务器以查看防病毒软件是否是最新的并且正在运行。棘手的是它们分布在 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/