Get antispyware name in Windows using C#

To detect installed anti-spyware’s name in Windows we need ManagementObjectSearcher class. To use it, we have to add a reference to the namespace System.Management.

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