Here's how to detect whether any 'Antivirus' is installed (using C#)


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.

 

 


If you have come this far, it means that you liked what you are reading. Why not reach little more and connect with me directly on Twitter, Facebook, Google+ and LinkedIn. I would love to hear your thoughts and opinions on my articles directly. Also, don't forget to share your views and/or feedback in the comment section below.

0 comments

 
© 2008-2016 Kunal-Chowdhury.com - Microsoft Technology Blog for developers and consumers | Designed by Kunal Chowdhury
Back to top