• 彻底关闭Win10自动更新的代码


    Windows 10 总是反反复复无休止的更新,然后自动(闲时)重启或者提示重启, 简直烦不胜烦...

    所以直接写了这个小程序,关闭所有自动更新项,一劳永逸.

           static void Main(string[] args)
            {
                Console.Title = "Disable Windows AutoUpdate";
                Console.WriteLine("Disable Windows 10 AutoUpdate");
                Console.WriteLine("Version:1.0");
                Console.WriteLine("Release:2021-01-21");
    
                DisableSvc();
    
                DisableReg();
                // 注册表修改或者手动处理:
                // 组策略:gpedit.msc -> 计算机配置 -> 管理模板 -> Windows组件 -> Windows更新:
                //    配置自动更新 -> 已禁用
                //    删除使用所有Windows更新功能的访问权限 -> 已启用
    
                DisableTaskScheduler();
    
                Console.WriteLine("All Windows Auto Update configuration was disabled.");
                Console.WriteLine("Please restart the system manually for the configuration to take effect.");
                Console.WriteLine("Press any key to exit...");
    
                Console.Read();
    
            }
    
    
            private static void DisableTaskScheduler()
            {
                try
                {
                    TaskSchedulerClass scheduler = new TaskSchedulerClass();
                    scheduler.Connect();
                    ITaskFolder folder = scheduler.GetFolder(@"MicrosoftWindowsWindowsUpdate");
                    foreach (IRegisteredTask task in folder.GetTasks(0))
                    {
                        task.Stop(0);
                        task.Enabled = false;
                        Console.WriteLine($"TaskSchedule [{task.Name}] was disabled.");
                    }
                    // eg. Scheduled Start
    
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
    
            private static void DisableReg()
            {
                // 注册还有个位置,但是不好判断,暂时不处理
                SetRegVal(
                    Microsoft.Win32.RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine,
                        Microsoft.Win32.RegistryView.Default), @"SOFTWAREPoliciesMicrosoftWindowsWindowsUpdateAU", "NoAutoUpdate", 1);
                // HKEY_USERSS-1-5-21-897350936-3504488752-3495779238-500SOFTWAREMicrosoftWindowsCurrentVersionGroup Policy Objects{C3BF0CDD-7FAF-4D58-BCA4-0A011084C32E}MachineSoftwarePoliciesMicrosoftWindowsWindowsUpdateAU
                Console.WriteLine($"Group Policy [WindowsUpdate\NoAutoUpdate] was disabled.");
                SetRegVal(
                    Microsoft.Win32.RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine,
                        Microsoft.Win32.RegistryView.Default), @"SOFTWAREPoliciesMicrosoftWindowsWindowsUpdate", "SetDisableUXWUAccess", 1);
                // HKEY_USERSS-1-5-21-897350936-3504488752-3495779238-500SOFTWAREMicrosoftWindowsCurrentVersionGroup Policy Objects{C3BF0CDD-7FAF-4D58-BCA4-0A011084C32E}MachineSoftwarePoliciesMicrosoftWindowsWindowsUpdate
                Console.WriteLine($"Group Policy [WindowsUpdate\SetDisableUXWUAccess] was enabled.");
            }
    
            private static void DisableSvc()
            {
                string[] svrs = new[] { @"wuauserv", @"UsoSvc", @"WaaSMedicSvc" };
                foreach (var svr in System.ServiceProcess.ServiceController.GetServices().Where(q => svrs.Contains(q.ServiceName)))
                {
                    try
                    {
                        SetSvcVal(svr.ServiceName, "Start", 4);
                        if (svr.Status==ServiceControllerStatus.Running)
                        {
                            svr.Stop();
                        }
                        Console.WriteLine($"Windows Service [{svr.DisplayName}] was disabled.");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }

    后续可以通过命令,查看系统是否还会经常自动重启?

    systeminfo | find "系统启动时间"

  • 相关阅读:
    VS2012的恢复默认窗口的基本常用设置
    在 CentOS 6.4 上安装 CloudStack 4.2
    centos7上安装mysql
    myeclipse安装aptana插件
    访问WEB-INF下的JSP (转载)
    通过字节流复制大文件内容到指定的文件
    java 通过bufferedReader和bufferedWriter 拷贝文件
    Date类获取日期的方法失效的解决办法
    java中string 类型的对象间比较的学习笔记
    ubuntu下搭建nfs服务器
  • 原文地址:https://www.cnblogs.com/honk/p/14308907.html
Copyright © 2020-2023  润新知