Get antivirus name on Windows using C#

To detect antivirus name in Windows we need ManagementObjectSearcher class. To use it, we have to add reference in the project to the namespace System.Management.

try
{
	ManagementObjectSearcher mos = null;
	//Windows Vista/7/8
	if (Environment.OSVersion.Version.Major > 5)
	{
		mos = new ManagementObjectSearcher(@"\" +
			Environment.MachineName + @"rootSecurityCenter2", 
                         "SELECT * FROM AntivirusProduct");
	}
	//Windows XP
	else
	{
		mos = new ManagementObjectSearcher(@"\" +
			Environment.MachineName + @"rootSecurityCenter", 
                         "SELECT * FROM AntivirusProduct");
	}
 
	ManagementObjectCollection moc = mos.Get();
 
	foreach (ManagementObject mo in moc)
		Console.WriteLine(mo["displayName"].ToString());
}
catch (Exception)
{
	//...
}
Categories: C# Tags: , , ,
%d bloggers like this: