彻底关闭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(@"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 "系統啟動時間"
總結
以上是生活随笔為你收集整理的彻底关闭Win10自动更新的代码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java字符串除法函数,java – 函
- 下一篇: mysql5.5索引,MySQL--5索