The Road to Delphi

Delphi – Free Pascal – Oxygene

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

4 Comments

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();
    }


  }
}

Unknown's avatar

Author: Rodrigo

Just another Delphi guy.

4 thoughts on “Detect if an antivirus software is installed in Windows using C#

  1. parneet384's avatar

    Is this coding be essential for every antivirus protection software ?

  2. babi's avatar

    Hi,

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

Leave a comment