Thursday, July 24, 2014

Check if Antivirus Software Installed

Today I want to show, how to check with C#, whether some Antivirus software is installed. We do this using a WMI query, in the linked post I gave a little introduction to that topic.
The path needed for this is root/SecurityCenter2/AntiVirusProduct, the query then returns for every installed Antivirus product an object with some attributes, amongst others of course name, product state, path to the executable and date (displayName, productState, pathToSignedProductExe und timestamp).
In the post linked above I also wrote about the WMI Object Browser, with which the WMI can be browsed and which explains the meaning of some attributes and classes. For the class used here unfortunately no explanation is existing though, online there is no real information as well.
For example I do not know, what timestamp is supposed to be, about the meaning of productState you here find a nice theory. I would appreciate hints and explanations a lot.
Our main goal though, the simply request whether an Antivirus program is installed and if yes, which, is reached, the code:
            ManagementObjectSearcher MySearcher =
               new ManagementObjectSearcher("root\\SecurityCenter2", "SELECT * FROM " + "AntiVirusProduct");

            string Result = "";

            foreach (ManagementObject queryObj in MySearcher.Get())
            {
                Result += "New Product:" + Environment.NewLine;
                foreach (PropertyData propertyData in queryObj.Properties)
                {
                    Result += propertyData.Name.ToString() + ":" + propertyData.Value.ToString() + Environment.NewLine;
                }
            }

No comments:

Post a Comment