在寻找答案的过程中,我多次看到类似于以下的代码示例:
using System;
using System.Text;
using System.Management;
namespace ConsoleApplication1
{
class Program
{
public static bool AntivirusInstalled()
{
string wmipathstr = @"\\" + Environment.MachineName + @"\root\SecurityCenter";
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher(wmipathstr, "SELECT * FROM AntivirusProduct");
ManagementObjectCollection instances = searcher.Get();
return instances.Count > 0;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
return false;
}
public static void Main(string[] args)
{
bool returnCode = AntivirusInstalled();
Console.WriteLine("Antivirus Installed " + returnCode.ToString());
Console.WriteLine();
Console.Read();
}
}
}
不幸的是,Windows Server 2008 似乎没有SecurityCenter
orSecurityCenter2
命名空间,所以我Invalid namespace
在尝试这种方法时遇到了异常。
有谁知道确定 Windows Server 2008 上是否运行防病毒软件的方法?任何帮助表示赞赏!