Please Refer script that allows you to disable the windows Auto update.
Note
- Run the script as "System user "
- This script will control windows 7 automatic update settings in local group policy level. In case windows 8 and above version it will stop and disable the necessary windows update services due to security restriction.
- You can also control automatic update settings available in the location "Computer Configuration\Administrative Templates\Windows \Components\Windows Update\Configure Automatic Updates" through GPO.
import os
import time,re
import platform
import ctypes
import _winreg
import subprocess
class disable_file_system_redirection:
_disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection
_revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection
def __enter__(self):
self.old_value = ctypes.c_long()
self.success = self._disable(ctypes.byref(self.old_value))
def __exit__(self, type, value, traceback):
if self.success:
self._revert(self.old_value)
def disable():
with disable_file_system_redirection():
osversion=platform.release()
print 'windows '+osversion
if str(osversion)=="10":
print os.popen(r'net.exe stop wuauserv').read()
os.popen('sc config "wuauserv" start= disabled')
elif "2008" in str(osversion):
print "Win 2008"
elif (("8" == str(osversion)) or ("8.1" == str(osversion)) or ("2012" in str(osversion))):
print os.popen(r'net.exe stop wuauserv').read()
print os.popen('sc config "wuauserv" start= disabled').read()
elif str(osversion)=="7":
print "Win 7"
keyVal = r'SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU'
try:
key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, keyVal, 0, KEY_ALL_ACCESS)
except:
key = _winreg.CreateKey(_winreg.HKEY_LOCAL_MACHINE, keyVal)
_winreg.SetValueEx(key, "AUOptions", 0, _winreg.REG_DWORD, 4)
_winreg.CloseKey(key)
else:
out="Windows xp , Vista, Windows server 2003 cannot be updated"
return(out)
disable()
20170524-Disable-Windows-update.json (2.61 KB)