1. 程式人生 > 實用技巧 >徹底關閉Win10自動更新的程式碼

徹底關閉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(@"\Microsoft\Windows\WindowsUpdate"); 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), @"SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU", "NoAutoUpdate", "1"); // HKEY_USERS\S-1-5-21-897350936-3504488752-3495779238-500\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy Objects\{C3BF0CDD-7FAF-4D58-BCA4-0A011084C32E}Machine\Software\Policies\Microsoft\Windows\WindowsUpdate\AU Console.WriteLine($"Group Policy [WindowsUpdate\\NoAutoUpdate] was disabled."); SetRegVal( Microsoft.Win32.RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, Microsoft.Win32.RegistryView.Default), @"SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate", "SetDisableUXWUAccess", "1"); // HKEY_USERS\S-1-5-21-897350936-3504488752-3495779238-500\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy Objects\{C3BF0CDD-7FAF-4D58-BCA4-0A011084C32E}Machine\Software\Policies\Microsoft\Windows\WindowsUpdate 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); } } }