The Road to Delphi

Delphi – Free Pascal – Oxygene

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

Leave a 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.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s