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

Many time during app development, developers need to find out whether any Antivirus software is installed in client's operating system. In case it is installed, we may want to know the installed antivirus software name.

 

If you are looking for such code (using .NET/C#), you came to the right place. Here we are going to see the code to retrieve this information.

 

How to programmatically detect, whether any antivirus software is already installed in system (www.kunal-chowdhury.com)

 

As people using computers, the need of a strong antivirus software increased due to high volume of viruses spreading each day. While building a system software, you may need to know whether any antivirus is already installed in the user's system. You can of course, get this information from Windows Registry; but that's not a full proof solution.

 

Windows operating system provides 'Windows Management Instrument' APIs aka. WMI, which provides you an option to check for it and grab the details. 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'

Here's the code to know whether any antivirus product is already installed in the system:

 

public static bool IsAntivirusProductInstalled()
{
    // prior to Windows Vista '\root\SecurityCenter'
    using (var searcher = new ManagementObjectSearcher(@"\\" +
                                        Environment.MachineName +
                                        @"\root\SecurityCenter",
                                        "SELECT * FROM AntivirusProduct"))
    {
        var searcherInstance = searcher.Get();
        if (searcherInstance.Count > 0) { return true; }
    }
 
    // for Windows Vista and above '\root\SecurityCenter2'
    using (var searcher = new ManagementObjectSearcher(@"\\" +
                                        Environment.MachineName +
                                        @"\root\SecurityCenter2",
                                        "SELECT * FROM AntivirusProduct"))
    {
        var searcherInstance = searcher.Get();
        if (searcherInstance.Count > 0) { return true; }
    }
 
    return false;
}

 

Make sure that, you query in both the 'SecurityCenter' to get the status of installed antivirus product. Hope you liked the above post. In next post, we will learn 'how to grab the installed antivirus product name'. So, stay tuned.

 

 

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.