简体   繁体   English

打开和关闭防病毒软件

[英]Turn on and off antivirus

Is there a way to detect whether there is an antivirus software installed in a machine using C#?有没有办法用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#?我知道安全中心检测到防病毒软件,但你如何在 C# 中检测到它?以及如何在 C# 中关闭和打开它?

How to detect it : See the following question: Detect Antivirus on Windows using C# 如何检测它 :请参阅以下问题: 使用C#在Windows上检测防病毒

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. 关闭防病毒软件应该始终是用户(或公司环境中的管理员)的明智选择,而不是第三方产品可以轻松完成的事情。

To return AntiVirus name as string:以字符串形式返回 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;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM