Follow us on X (Twitter)  Like us on Facebook  Connect with us on LinkedIn  Subscribe to our YouTube Channel  Subscribe to our WhatsApp Group

In the last blog post, we discussed the C# code to detect whether any antivirus product is already installed in the system. In today's blog post we will learn how to retrieve the installed antivirus software name from the Security Center.

 

Continue reading to grab the source code and discuss more on the API set exposed by the Framework. If you have any queries, do let me know.

 

How to programmatically detect installed antivirus software (www.kunal-chowdhury.com)

 

Operating System is the heart of your computer. It can be affected by Viruses, which are nothing but the programs written to harm your system. For this, we need antivirus to detect any suspicious code or viruses that can harm your system.

 

It's not a recommended way to install multiple antivirus products running in a single system. If you are building such software, you may need to detect already installed antivirus. Read the post 'How to detect whether any antivirus is installed in the system' for further details.

 

Now let's learn the code to retrieve the name of all such products. As discussed in the previous blog post, the 'Windows Management Instrument' APIs aka. WMI is going to help you on this.

If you are using .NET/C#, you can use the API class 'ManagementObjectSearcher' which is available under the 'System.Management' namespace.

 

To implement this, you need to search for the 'AntivirusProduct' family in proper location of WMI Security Center and then iterate through the search instance to grab details. Note the following points before starting:

    • 'Security Center' for WMI prior to Windows Vista is: '\root\SecurityCenter'
    • 'Security Center' for WMI for Windows Vista and above is: '\root\SecurityCenter2'

The searcher instance will return you the value based on the key 'displayName' passed to it. Here's the code for you to refer:

 

public static void ListInstalledAntivirusProducts()
{
    // prior to Windows Vista '\root\SecurityCenter'
    using (var searcher = new ManagementObjectSearcher(@"\\" +
                                        Environment.MachineName +
                                        @"\root\SecurityCenter",
                                        "SELECT * FROM AntivirusProduct"))
    {
        var searcherInstance = searcher.Get();
        foreach (var instance in searcherInstance)
        {
            Console.WriteLine(instance["displayName"].ToString());
        }
    }
 
    // for Windows Vista and above '\root\SecurityCenter2'
    using (var searcher = new ManagementObjectSearcher(@"\\" +
                                        Environment.MachineName +
                                        @"\root\SecurityCenter2",
                                        "SELECT * FROM AntivirusProduct"))
    {
        var searcherInstance = searcher.Get();
        foreach (var instance in searcherInstance)
        {
            Console.WriteLine(instance["displayName"].ToString());
        }
    }
}

 

Make sure that, you query in both the 'SecurityCenter' to get the status of installed antivirus product as well as the name of the product.

 

The code is also available as part of NuGet. In your Visual Studio IDE, execute the following command from NuGet Package Manager to download the binaries in your project. The 'SystemHelper' class exposes two API methods to detect status of installed antivirus as well as the name of the product. Do try it:

 

How to install 'WinLab.Windows.Helpers.System' library from NuGet (www.kunal-chowdhury.com)

 

Hope you liked the above post. If you have any queries or comments, drop a line below. Have a great day!

 

 

Have a question? Or, a comment? Let's Discuss it below...

dhgate

Thank you for visiting our website!

We value your engagement and would love to hear your thoughts. Don't forget to leave a comment below to share your feedback, opinions, or questions.

We believe in fostering an interactive and inclusive community, and your comments play a crucial role in creating that environment.