Enable Windows Auto update

Please Refer script that allows you to enable the windows Auto update .

Note:

  • Run the script as "System user "
  • This script will set Windows 7 automatic update settings as "Check for an update and notify before download and install" in local group policy level.
  • In the case of Windows 8 and above version it will make sure that necessary windows update services are being run, as complete background control is restricted
  • You can also control automatic update settings of all your network endpoints by changing "Computer Configuration\Administrative Templates\Windows \Components\Windows Update\Configure Automatic Updates" options available in the group policy management of your Domain controller.


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 enable():
    with disable_file_system_redirection():
        osversion=platform.release()
        print 'windows '+osversion
        if str(osversion)=="10":
            r='sc config "wuauserv" start= auto'
            print os.popen(r).read()
            q=os.popen("net.exe  start wuauserv",).read()
            print q
            r=subprocess.Popen("net.exe  start wuauserv",stderr=subprocess.PIPE)
            out=r.communicate()
            print os.popen("wuauclt.exe  /resetauthorization  /scannow").read()

        elif "2008" in str(osversion):
            print "Win 2008"
        elif (("8" == str(osversion)) or ("8.1" == str(osversion)) or ("2012" in str(osversion))):
            r='sc config "wuauserv" start= auto'
            print os.popen(r).read()
            q=os.popen("net.exe  start wuauserv",).read()
            print q
            r=subprocess.Popen("net.exe  start wuauserv",stderr=subprocess.PIPE)
            out=r.communicate()
            print os.popen("wuauclt.exe  /resetauthorization  /scannow").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, 2)
                _winreg.CloseKey(key)
        else:
            out="Windows xp , Vista, Windows server 2003 cannot be updated"
            return(out)

enable()


Sample output :

20170524-Enable-Windows-Update.json (3.24 KB)