I have seen code samples similar to the following numerous times in my search for an answer:
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();
}
}
}
Unfortunately, it appears that Windows Server 2008 does not have the SecurityCenter
or SecurityCenter2
namespace, so I get an Invalid namespace
exception when trying this approach.
Does anyone know of a way to determine if there is antivirus software running on Windows Server 2008? Any help is appreciated!
return instances.Any();
instead ofCount > 0
- ifinstances
is a very long list, counting all the members just to see if they are more than zero is a bad idea :) – MammillateERROR Description = Invalid Namespace
– PirogueSecurityCenter
namespaces do not exist on Server 2003/2008 – Sailmaker