The Road to Delphi

Delphi – Free Pascal – Oxygene

Detect if an antivirus software is installed in Windows using Delphi Prism

1 Comment

The next code show how detect if an antivirus software is installed in Windows using Delphi Prism (Oxygene) and the WMI.

uses
System,
System.Management,
System.Text;

type
  ConsoleApp = class
    private
      class method AntivirusInstalled() : Boolean;
    public
      class method Main;
  end;

implementation

class method ConsoleApp.Main;
begin
  var returnCode : Boolean := AntivirusInstalled();
  Console.WriteLine("Antivirus Installed " + returnCode.ToString());
  Console.WriteLine();
  Console.Read();
end;

class method ConsoleApp.AntivirusInstalled() : Boolean;
begin
   var wmipathstr :string  := "\\" + Environment.MachineName + "\root\SecurityCenter";//since windows vista you must use the SecurityCenter2 namespace
    try
       var searcher  : ManagementObjectSearcher    := New ManagementObjectSearcher(wmipathstr, "SELECT * FROM AntivirusProduct");
       var instances : ManagementObjectCollection  := searcher.Get();
       result:=(instances.Count > 0);
    except on E: Exception do
      begin
        Console.WriteLine(e.Message);
        Result:=False;
      end;
    end;
end;

Author: Rodrigo

Just another Delphi guy.

One thought on “Detect if an antivirus software is installed in Windows using Delphi Prism

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s