Share: Reset Windows Update

Share your tips or issues concerning the WAPT Console or WAPT Agent here
Forum Rules
Community Forum Rules
* English support on www.reddit.com/r/wapt
* French community support is available on this forum
* Please prefix the topic title with [RESOLVED] if it is resolved.
* Please do not edit a topic that is tagged [RESOLVED]. Open a new topic referencing the old one.
* Specify the installed WAPT version, full version, and build number (2.2.1.11957 / 2.2.2.12337 / etc.) as well as the Enterprise/Discovery edition.
* Versions 1.8.2 and earlier are no longer supported. The only questions accepted regarding version 1.8.2 are related to upgrading to a supported version (2.1, 2.2, etc.).
* Specify the server OS (Linux/Windows) and version (Debian Buster/Bullseye - CentOS 7 - Windows Server 2012/2016/2019).
* Specify the OS of the administration/package creation machine and the machine with the problematic agent, if applicable (Windows 7/10/11/Debian 11/etc.).
* Avoid asking multiple questions when opening a topic, otherwise it may be ignored. If there are multiple topics, open separate topics, preferably one after the other and not all at the same time (i.e., do not spam the forum).
* Include code snippets, screenshots, and other images directly in the post. Links to Pastebin, Bitly, and other third-party sites will be systematically removed.
* As with any community forum, support is provided voluntarily by members. If you require commercial support, you can contact Tranquil IT's sales department at 02.40.97.57.55
Locked
User avatar
t.heroult
Messages: 307
Registration: December 8, 2020 - 10:13 AM

June 9, 2022 - 2:10 PM

Hello everyone.
I'm sharing with you a small package I developed to solve quite a few problems with WindowsUpdate.
In fact, it's a compilation of the main actions known to troubleshoot a failing WindowsUpdate.

Actions taken:
  • DNS Flush
  • Purges:
  • - "qmgr*.dat" files in ALLUSERSPROFILE/Application Data/Microsoft/Network/Downloader
  • - "qmgr*.dat" files in ALLUSERSPROFILE/Microsoft/Network/Downloader
  • - All files in WINDIR/Logs/WindowsUpdate
  • Folder deletions (they will be rebuilt when the Windows Update service starts):
  • - WINDIR/SoftwareDistribution
  • - SYSTEM32/Catroot2
  • Registry key deletion:
  • - HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate
  • - HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\WindowsUpdate
  • GPUPDATE (at the machine level)
  • Reset the "bits" service
  • Resetting the “Windows Update” service
  • Re-registering some DLLs
  • Winsock reset
  • Configuring service startup
  • Restart services if necessary
  • If Waptwua is active, then disable the Windows Update service
And here is the code:

Code: Select all

def install():
    print("Arrêt des services :")
    Stop_Service_if_needed('bits',"- Background Intelligent Transfer Service (bits).")
    Stop_Service_if_needed('wuauserv',"- Windows Update (wuauserv).")
    Stop_Service_if_needed('appidsvc',"- Application Identity (appidsvc).")
    Stop_Service_if_needed('cryptsvc',"- Cryptographic Services (cryptsvc).")

    print("Flush DNS")
    run("Ipconfig /flushdns")
    dossier = makepath(os.environ.get('ALLUSERSPROFILE'),'Application Data','Microsoft','Network','Downloader')
    if isdir(dossier):
        fichiers = find_all_files(dossier,include_patterns='qmgr*.dat')
        print('Purge des fichiers "qmgr*.dat" de ' + dossier)
        for fichier in fichiers:
            remove_file(fichier)
            print("Suppression de : " + fichier)

    dossier = makepath(os.environ.get('ALLUSERSPROFILE'),'Microsoft','Network','Downloader')
    if isdir(dossier):
        fichiers = find_all_files(dossier,include_patterns='qmgr*.dat')
        print('Purge des fichiers "qmgr*.dat" de ' + dossier)
        for fichier in fichiers:
            remove_file(fichier)
            print("Suppression de : " + fichier)

    dossier = makepath(os.environ.get('WINDIR'),'Logs','WindowsUpdate')
    if isdir(dossier):
        fichiers = find_all_files(dossier)
        print('Purge du dossier ' + dossier)
        for fichier in fichiers:
            remove_file(fichier)
            print("Suppression de : " + fichier)

    f_pending_xml = makepath(os.environ.get('WINDIR'),'winsxs','pending.xml')
    if isfile(f_pending_xml + '.bak'):
        remove_file(f_pending_xml + '.bak')
    if isfile(f_pending_xml):
        print("sauvegarde de " + f_pending_xml)
        os.rename(f_pending_xml,f_pending_xml + '.bak')

    dossier = makepath(os.environ.get('WINDIR'),'SoftwareDistribution')
    if isdir(dossier):
        print("Suppression de " + dossier)
        remove_tree(dossier)

    dossier = makepath(system32,'Catroot2')
    if isdir(dossier):
        print("Suppression de " + dossier)
        remove_tree(dossier)

    if reg_key_exists(HKEY_LOCAL_MACHINE,'SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate'):
        print('Purge de la clé de registe : HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate')
        registry_deletekey(HKEY_LOCAL_MACHINE,'SOFTWARE\Policies\Microsoft\Windows','WindowsUpdate')
    if reg_key_exists(HKEY_LOCAL_MACHINE,'SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\WindowsUpdate'):
        print('Purge de la clé de registe : HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\WindowsUpdate')
        registry_deletekey(HKEY_LOCAL_MACHINE,'SOFTWARE\Microsoft\Windows\CurrentVersion\Policies','WindowsUpdate')

    print("GPUPDATE (ordinateur)")
    run('gpupdate /force /target:computer')

    print('Reset du service "bits"')
    run('sc.exe sdset bits D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;AU)(A;;CCLCSWRPWPDTLOCRRC;;;PU)')
    print('Reset du service "Windows Update"')
    run('sc.exe sdset wuauserv D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;AU)(A;;CCLCSWRPWPDTLOCRRC;;;PU)')

    lst_dlls = ['atl.dll','urlmon.dll','mshtml.dll','shdocvw.dll','browseui.dll','jscript.dll','vbscript.dll','scrrun.dll','msxml.dll','msxml3.dll','msxml6.dll','actxprxy.dll','softpub.dll','wintrust.dll','dssenh.dll','rsaenh.dll','gpkcsp.dll','sccbase.dll','slbcsp.dll','cryptdlg.dll','oleaut32.dll','ole32.dll','shell32.dll','initpki.dll','wuapi.dll','wuaueng.dll','wuaueng1.dll','wucltui.dll','wups.dll','wups2.dll','wuweb.dll','qmgr.dll','qmgrprxy.dll','wucltux.dll','muweb.dll','wuwebv.dll','wudriver.dll']
    print("Ré-enregistrement de quelques dlls.")
    for f_dll in lst_dlls:
        fichier = makepath(system32,f_dll)
        run_notfatal('regsvr32.exe /s %s' % fichier)

    print("Réinitialisation du winsock.")
    run('netsh winsock reset')
    run('netsh winsock reset proxy')

    print("Configuration des services")
    run_notfatal('sc config wuauserv start= auto')
    run_notfatal('sc config bits start= auto ')
    run_notfatal('sc config DcomLaunch start= auto')


    print("Redémarrage des services selon leur propriété 'startup'")
    Start_Service_if_needed('bits',"- Background Intelligent Transfer Service (bits).")
    Start_Service_if_needed('wuauserv',"- Windows Update (wuauserv).")
    Start_Service_if_needed('appidsvc',"- Application Identity (appidsvc).")
    Start_Service_if_needed('cryptsvc',"- Cryptographic Services (cryptsvc).")

    # Si WAPTwua est actif sur la cible, alors désactivation et arrêt du service Windows Update
    if inifile_hassection(WAPT.config_filename,'waptwua'):
        waptwua_setting = inifile_readstring(WAPT.config_filename,'waptwua','enabled')
        if (waptwua_setting == 'True' or waptwua_setting == '1'):
            print("Waptwua est activé sur ce poste.")
            run_notfatal('sc config wuauserv start= disabled')
            Stop_Service_if_needed('wuauserv',"- Désactivation et arrêt du service Windows Update.")

    pass
    # put here what to do when package is installed on host
    # implicit context variables are WAPT, basedir, control, user, params, run

def Start_Service_if_needed(Service,DisplayInfo):
    if service_installed(Service):
        if not service_is_running(Service):
            key = reg_openkey_noredir(HKEY_LOCAL_MACHINE,'SYSTEM\CurrentControlSet\Services\%s' % (Service),KEY_READ)
            startup = reg_getvalue(key,'Start')
            if startup == '2':
                print(DisplayInfo)
                service_start(Service)

def Stop_Service_if_needed(Service,DisplayInfo):
    if service_installed(Service):
        if service_is_running(Service):
            print(DisplayInfo)
            service_stop(Service)
Sincerely,
Tom
Server: WAPT Enterprise 2.6.1.17786 on Debian
Consoles: Windows 10 & 11
Infrastructure: Windows

Did you know? When parrotfish undergo smoltification, their osmoregulation mechanism is reversed!
User avatar
erenodau
Messages: 28
Registration: February 20, 2019 - 10:42
Location: Saint Sébastien sur Loire
Contact :

June 9, 2022 - 4:46 PM

Hello,

thank you for sharing, it looks very interesting!

Have a good day and see you soon!
Locked