The next code shows how detect if an antivirus software is installed in Windows using C# and the WMI.
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(); } } }
October 15, 2009 at 4:20 am
Is this c# coding be used for every antivirus protection?
October 15, 2009 at 1:04 pm
The code uses WMI, so it depends if the WMI recognize or not the antivirus, in 99% of cases it works, recognizing the antivirus.
October 15, 2009 at 4:22 am
Is this coding be essential for every antivirus protection software ?
May 18, 2010 at 5:04 pm
Hi,
I am trying this code in Windows 7. It doesn’t seem to be working.
Any idea?