Skip to content
The Road to Delphi — Delphi, VCL, VCL Styles, UxTheme and WinAPI

Detect if an antivirus software is installed in Windows using C#

, ,

The next code shows how detect if an antivirus software is installed in Windows using C# and the WMI.

[sourcecode language=”csharp”]
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();
}

}
}

[/sourcecode]

4 responses

  1. Is this c# coding be used for every antivirus protection?

    1. The code uses WMI, so it depends if the WMI recognize or not the antivirus, in 99% of cases it works, recognizing the antivirus.

  2. Is this coding be essential for every antivirus protection software ?

  3. Hi,

    I am trying this code in Windows 7. It doesn’t seem to be working.
    Any idea?

Leave a Reply