使用C#关闭 windows defender服务

1.直接操作注册表
路径:
计算机\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SecurityHealthService
修改start属性的值 REG_DWORD 为4

2.使用C#编码实现

using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.WriteLine("i love my mother");
     
            //
            var localmachine = Registry.LocalMachine;
            //var windefer = localmachine.GetValue(@"SYSTEM/CurrentControlSet/Services/SecurityHealthService/start");        
            var windefer = localmachine.OpenSubKey("SYSTEM").OpenSubKey("CurrentControlSet").OpenSubKey("Services")
                .OpenSubKey("SecurityHealthService",true);
            //
            
            //Console.WriteLine("{0}", windefer.GetValue("start").ToString());
            //
            //Console.WriteLine("{0}",    "开始写注册表");
            Console.WriteLine("{0}", "启动关闭Windows Defender");
            try
            {
                windefer.SetValue("start", 4);
            }catch(Exception e)
            {
                Console.WriteLine("{0},{1}","需要权限支持",e.Message);
            }
      
            //Console.WriteLine("{0}",    "结束写注册表");
            Console.WriteLine("{0}", "结束关闭Windows Defender");
            //
            Console.ReadKey();
        }
    }
}

3.运行上述程序生成的程序(需要管理员权限

修改后的注册表结果

//
应用程序下载
https://kdocs.cn/l/sr76fATZ9fY4
[金山文档] WinDefenderClose.exe

//gitee源码
https://gitee.com/tiplatform/windefenderclose.git

posted @ 2021-09-27 22:13  iwetuan  阅读(352)  评论(0编辑  收藏  举报