I need a better way to query installed antivirus. Something like this in c# Perhaps?

1.5k views Asked by At

Is there a C# equivalent to this? I have tried using WMI and simply get "Windows Defender" regardless of the installed WMI compliant AntiVirus.

I simply want to display these results in a textbox.

WMIC /Node:localhost /Namespace:\\root\SecurityCenter2 Path AntiVirusProduct         Get displayName /Format:List 

When I use the code above I get the actual name of my AntiVirus.

1

There are 1 answers

6
Reza Aghaei On BEST ANSWER

You can add a reference to System.Management. Then using ManagementObjectSearcher you can run a WMI query.

To find installed antiviruses you should search in SecurityCenter2. For example:

var path = string.Format(@"\\{0}\root\SecurityCenter2", Environment.MachineName);
var searcher = new ManagementObjectSearcher(path, "SELECT * FROM AntivirusProduct");
var instances = searcher.Get().Cast<ManagementObject>()
                        .Select(x => (string)x.GetPropertyValue("displayName"))
                        .ToList();

Note 1: For Windows XP, search in SecurityCenter.

Note 2: You can also read other properties of the AntiVirusProduct:

  • displayName : string
  • instanceGuid : string
  • pathToSignedProductExe : string
  • pathToSignedReportingExe : string
  • productState : UInt32. (For information on how to parse the status, take a look at this post.)
  • timestamp : string