Comments

4 comments

  • Todd Scallions

    I used this on XP through 2012r2 with no issues.

    Copy/Paste into a txt file and save as .bat

    Create deploy package.

     

     

    @echo off
    cls
    REM ==================================================================================
    REM DESCRIPTION    : This script resets all of Windows Update Agent settings.
    REM AUTHOR         : Luca Fabbri
    REM VERSION HISTORY: 1.2 - Stop SMS Host Agent (SCCM Client) Service added
    REM                  1.0 - Start
    REM ==================================================================================
    @echo 1. Stopping Automatic Updates, BITS and SMS Host Agent Services...
    net stop wuauserv
    net stop bits
    net stop ccmexec
    @echo 2. Deleting AU cache folder and log file...
    del /f /q %SystemRoot%\WindowsUpdate.log
    del /f /s /q %SystemRoot%\SoftwareDistribution\*.*
    REM @echo 2. Renaming AU cache folder and log file...
    REM ren %SystemRoot%\WindowsUpdate.log %SystemRoot%\WindowsUpdate.bak
    REM ren %SystemRoot%\SoftwareDistribution %SystemRoot%\SoftwareDistribution.bak
    @echo 3. Re-registering DLL files...
    %SystemRoot%\system32\regsvr32.exe /s %SystemRoot%\system32\atl.dll
    %SystemRoot%\system32\regsvr32.exe /s %SystemRoot%\system32\jscript.dll
    %SystemRoot%\system32\regsvr32.exe /s %SystemRoot%\system32\msxml3.dll
    %SystemRoot%\system32\regsvr32.exe /s %SystemRoot%\system32\softpub.dll
    %SystemRoot%\system32\regsvr32.exe /s %SystemRoot%\system32\wuapi.dll
    %SystemRoot%\system32\regsvr32.exe /s %SystemRoot%\system32\wuaueng.dll
    %SystemRoot%\system32\regsvr32.exe /s %SystemRoot%\system32\wuaueng1.dll
    %SystemRoot%\system32\regsvr32.exe /s %SystemRoot%\system32\wucltui.dll
    %SystemRoot%\system32\regsvr32.exe /s %SystemRoot%\system32\wups.dll
    %SystemRoot%\system32\regsvr32.exe /s %SystemRoot%\system32\wups2.dll
    %SystemRoot%\system32\regsvr32.exe /s %SystemRoot%\system32\wuweb.dll
    @echo 4. Removing WSUS Client Id...
    REG DELETE "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate" /v AccountDomainSid /f
    REG DELETE "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate" /v PingID /f
    REG DELETE "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate" /v SusClientId /f
    @echo 5. Starting Automatic Updates, BITS and SMS Host Agent Services...
    net start ccmexec
    net start bits
    net start wuauserv
    @echo 6. Forcing AU discovery...
    wuauclt /resetauthorization /detectnow

     

    0
    Comment actions Permalink
  • Jack Flint

    Thank you! I'll give it a try!

    0
    Comment actions Permalink
  • Lee West

    This is what I use. Stops WUAU, Resets the AU settings, clears the software distribution folder and adds our WSUS keys, restarts the AU and the set off an update check. 

    It then reports back if machines need more updates or not to a set of folders on a specified server. I used VBSEdit to roll it up into an EXE and it works every time.

    Built from a few other scripts from other sources, so I can't take credit, but give it a whirl and see what you think.

    -------------------------------------------------------------------------------------------------------------------------------------

    Option Explicit
    Dim WshNetwork,updateSession,updateSearcher,searchResult,installationResult,updatesToDownload,updatesToInstall,downloader,update,installer,objshell,ComputerName,objTextFile,File,Shell,Network,objNetwork,AppShell,objOutputFile,strComputer,objFSO,strServiceName,objWMIService,colListOfServices,objService
    Dim i: i = 0

    Set Shell = CreateObject("WScript.Shell")
    Set Network = CreateObject("WScript.Network")
    Set objNetwork = CreateObject("Wscript.Network")
    Set AppShell = CreateObject("Shell.Application")
    Set File = CreateObject("Scripting.FileSystemObject")
    Set WshNetwork = CreateObject("WScript.Network")
    strServiceName = "wuauserv"
    Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
    Set colListOfServices = objWMIService.ExecQuery("Select * from Win32_Service Where Name ='" & strServiceName & "'")

    ComputerName = WshNetwork.ComputerName

    'Stopping Windows Update service
    For Each objService in colListOfServices
    objService.StopService()
    Next

    WScript.Sleep 1000

    'Applying Windows Update settings
    Shell.Run "regedit /s \\SERVERNAME\netlogon\TASKS\AUOnReg.reg"

    WScript.Sleep 1000

    'Delete SoftwareDistribution
    dim wshShell
    Set WshShell = WScript.CreateObject("WScript.Shell")
    WshShell.Run """\\bricht\pdq$\windowsupdate\DelSoftwareDistContents.bat"""
    WScript.Sleep 1000

    'Starting Windows Update service
    For Each objService in colListOfServices
    objService.StartService()
    Next

    WScript.Sleep 1000

    Set updateSession = CreateObject("Microsoft.Update.Session")
    Set updateSearcher = updateSession.CreateupdateSearcher()
    Set searchResult = updateSearcher.Search("IsInstalled=0 and Type='Software'")
    If searchResult.Updates.Count = 0 Then
    If (File.FileExists("\\SERVERNAME\WUlog$\1-Requires\" & ComputerName & ".txt")) Then
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    objFSO.MoveFile "\\SERVERNAME\WUlog$\1-Requires\" & ComputerName & ".txt", "\\Holst\WUlog$\2-Complete" & ComputerName & ".txt"
    Else
    Set objOutputFile = File.CreateTextFile("\\SERVERNAME\WUlog$\2-Complete\" & ComputerName & ".txt", True)
    objOutputFile.WriteLine(123)
    objOutputFile.Close
    End If
    WScript.Quit
    End If
    Set updatesToDownload = CreateObject("Microsoft.Update.UpdateColl")
    For i = 0 To searchResult.Updates.Count - 1
    Set update = searchResult.Updates.Item(i)
    updatesToDownload.Add(update)
    Next
    Set downloader = updateSession.CreateUpdateDownloader()
    downloader.Updates = updatesToDownload
    downloader.Download()
    Set updatesToInstall = CreateObject("Microsoft.Update.UpdateColl")
    For i = 0 To searchResult.Updates.Count - 1
    Set update = searchResult.Updates.Item(i)
    If update.IsDownloaded = True Then updatesToInstall.Add(update)
    Next
    Set installer = updateSession.CreateUpdateInstaller()
    installer.Updates = updatesToInstall
    Set installationResult = installer.Install()
    If installationResult.RebootRequired Then
    Set objOutputFile = File.CreateTextFile("\\SERVERNAME\WUlog$\1-Requires\" & ComputerName & ".txt", True)
    objOutputFile.WriteLine(123)
    objOutputFile.Close
    CreateObject("WScript.Shell").Run "shutdown.exe /r /t 0"
    End If

    0
    Comment actions Permalink
  • Jack Flint

    Thank you Lee West. For everyone's information the first script submitted does not work for Windows 10. I updated the script based on article in the OP but it did not clear up the issue. I'd prefer not to use VB Script and am trying a pure batch solution. I'll report my results either way.

    0
    Comment actions Permalink

Please sign in to leave a comment.