2

Is there a way to detect whether there is an antivirus software installed in a machine using C#? I know the Security Center detects antivirus software but how can you detect that in C#?And how to turn it off and on in C#?

Mat
  • 202,337
  • 40
  • 393
  • 406

2 Answers2

5

How to detect it: See the following question: Detect Antivirus on Windows using C#

How to turn it off and on: As far as I know, there is no simple, common way to turn off anti-virus software. And that's a good thing! Turning off anti-virus software should always be a conscious choice of the user (or the administrator in a corporate environment) and not be something that can be done easily by a third-party product.

Community
  • 1
  • 1
Heinzi
  • 167,459
  • 57
  • 363
  • 519
  • Yeah... Imagine the malware you (accidentially) installed from the internet could do something like that... – Nuffin Mar 29 '12 at 06:38
  • @Heinzi thanks for the link . But it tells only that antivirus is installed or not ? Can we code in such a way that we can get the name of antivirus installed too. – user1297661 Mar 29 '12 at 06:47
  • @user1297661: Instead of just checking `instances.Count`, you can read the `displayName` property of the `AntiVirusProduct` record. See this page for a code example: http://www.codeproject.com/Articles/37714/Software-Development-Build-your-own-Windows-Securi – Heinzi Mar 29 '12 at 07:37
  • Is it possible to decide wheter it is enabled. If I turn off for 10 minutes my antivirus software, the above link still says it is installed. I wan't to know if it is Enabled – Tomi Feb 15 '17 at 19:40
0

To return AntiVirus name as string:

 public static string Antivirus()
    {
        try
        {
            string firewallName = string.Empty;
            // starting with Windows Vista we must use the root\SecurityCenter2 namespace

            using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"\\" + Environment.MachineName + @"\root\SecurityCenter2", "Select * from AntivirusProduct"))
            {
                foreach (ManagementObject mObject in searcher.Get())
                {
                    firewallName += mObject["displayName"].ToString() + "; ";
                }
            }
            firewallName = RemoveLastChars(firewallName);

            return (!string.IsNullOrEmpty(firewallName)) ? firewallName : "N/A";
        }

        catch
        {
            return "Unknown";
        }
    }
    public static string RemoveLastChars(string input, int amount = 2)
    {
        if (input.Length > amount)
            input = input.Remove(input.Length - amount);
        return input;
    }
BBitar
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 03 '21 at 19:08