打开和关闭防病毒软件

本文关键字:防病毒 软件 | 更新日期: 2023-09-27 18:29:34

有没有办法检测使用C#的机器中是否安装了防病毒软件?我知道安全中心检测防病毒软件,但你怎么能在C#中检测到呢?以及如何在C#中关闭和打开它?

打开和关闭防病毒软件

如何检测:请参阅以下问题:使用C#在Windows上检测防病毒软件

如何关闭和打开:据我所知,没有简单、常见的方法可以关闭防病毒软件。这是一件好事!关闭防病毒软件应该始终是用户(或公司环境中的管理员)的自觉选择,而不是第三方产品可以轻松完成的事情。

以字符串形式返回AntiVirus名称:

 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;
    }