This shows you the differences between two versions of the page.
userspace:windows_updates_wsus_required_alternate_version [2013/02/06 17:10] WRatzka created |
userspace:windows_updates_wsus_required_alternate_version [2021/08/23 08:37] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== wsusclient ====== | ||
- | The following script was developed starting from a VBScript snippet from Microsoft | ||
- | (source: http:// | ||
- | and serves to force installing available updates from a WSUS server. | ||
- | The script comes in two parts, | ||
- | * '' | ||
- | * '' | ||
- | |||
- | The WSUS configuration can be controlled via properties // | ||
- | |||
- | This script has been tested on Windows XP (32bit) and Windows 7 (64bit). | ||
- | |||
- | ===== setup.ins ===== | ||
- | <code winst> | ||
- | [Actions] | ||
- | DefVar $NTVersion$ | ||
- | DefVar $ExitCode$ | ||
- | DefVar $WuAuVer$ | ||
- | DefVar $CurrentWsusUrl$ | ||
- | DefVar $WsusUrl$ | ||
- | DefVar $TargetGroup$ | ||
- | DefVar $NeedReboot$ | ||
- | DefVar $Failed$ | ||
- | DefVar $LogDir$ | ||
- | ; | ||
- | Set $LogDir$ = " | ||
- | ; | ||
- | set $WsusUrl$ = GetProductProperty(" | ||
- | set $TargetGroup$ = GetProductProperty(" | ||
- | ; | ||
- | set $NeedReboot$ = " | ||
- | set $Failed$ = " | ||
- | |||
- | ShowBitmap " | ||
- | |||
- | Set $NTVersion$ = GetNTVersion | ||
- | |||
- | if ( $NTVersion$ = " | ||
- | |||
- | if (GetRegistryStringValue32(" | ||
- | |||
- | dosinanicon_wsusclientcleanup_xp | ||
- | |||
- | if (GetRegistryStringValue(" | ||
- | Message " | ||
- | winbatchinstall_KB898461 | ||
- | Sub_check_exitcode | ||
- | endif | ||
- | |||
- | if (GetRegistryStringValue(" | ||
- | Message " | ||
- | winbatchinstall_KB942288-v3 | ||
- | Sub_check_exitcode | ||
- | endif | ||
- | |||
- | set $WuAuVer$ = getValue(" | ||
- | |||
- | if (CompareDotSeparatedNumbers(" | ||
- | Message " | ||
- | winbatchinstall_wuau | ||
- | Sub_check_exitcode | ||
- | endif | ||
- | |||
- | |||
- | if ($Failed$ = " | ||
- | LogError " | ||
- | IsFatalError | ||
- | else | ||
- | Registry_MarkReboot | ||
- | comment " | ||
- | exitWindows / | ||
- | endif | ||
- | endif | ||
- | endif | ||
- | |||
- | [Registry_MarkReboot] | ||
- | OpenKey [HKEY_LOCAL_MACHINE\Software\HRZMR] | ||
- | Set " | ||
- | |||
- | [Registry_UnmarkReboot] | ||
- | OpenKey [HKEY_LOCAL_MACHINE\Software\HRZMR] | ||
- | DeleteVar " | ||
- | |||
- | |||
- | [winbatchinstall_KB898461] | ||
- | %scriptpath%\WindowsXP-KB898461-x86-ENU.exe -n -q -z | ||
- | |||
- | [winbatchinstall_KB942288-v3] | ||
- | %scriptpath%\WindowsXP-KB942288-v3-x86.exe -n -q -z | ||
- | |||
- | [winbatchinstall_wuau] | ||
- | %scriptpath%\WindowsUpdateAgent30-x86.exe /quiet /norestart | ||
- | |||
- | [Sub_check_exitcode] | ||
- | comment "Test for installation success via exit code" | ||
- | set $ExitCode$ = getLastExitCode | ||
- | ; informations to exit codes see | ||
- | ; http:// | ||
- | ; http:// | ||
- | if ($ExitCode$ = " | ||
- | comment "Looks good: setup program gives exitcode zero" | ||
- | else | ||
- | comment "Setup program gives a exitcode unequal zero: " + $ExitCode$ | ||
- | if ($ExitCode$ = " | ||
- | comment " | ||
- | comment " | ||
- | else | ||
- | if ($ExitCode$ = " | ||
- | comment "looks good: setup program gives exitcode 1641" | ||
- | comment " | ||
- | Set $NeedReboot$ = " | ||
- | else | ||
- | if ($ExitCode$ = " | ||
- | comment "looks good: setup program gives exitcode 3010" | ||
- | comment " | ||
- | Set $NeedReboot$ = " | ||
- | else | ||
- | logError " | ||
- | Set $Failed$ = " | ||
- | endif | ||
- | endif | ||
- | endif | ||
- | endif | ||
- | |||
- | [dosinanicon_wsusclientcleanup_xp] | ||
- | |||
- | net stop wuauserv | ||
- | net stop bits | ||
- | |||
- | msiexec / | ||
- | regsvr32 /s /u wuapi.dll | ||
- | regsvr32 /s /u wuaueng1.dll | ||
- | regsvr32 /s /u wuaueng.dll | ||
- | regsvr32 /s /u wucltui.dll | ||
- | regsvr32 /s /u wups2.dll | ||
- | regsvr32 /s /u wups.dll | ||
- | regsvr32 /s /u wuweb.dll | ||
- | |||
- | rmdir /s /q %windir%\SoftwareDistribution | ||
- | |||
- | reg delete HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate /f | ||
- | reg delete HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate /f | ||
- | |||
- | if exist %windir%\WindowsUpdate.log.%date%.bak del %windir%\WindowsUpdate.log.%date%.bak | ||
- | if exist %windir%\WindowsUpdate.log ren %windir%\WindowsUpdate.log WindowsUpdate.log.%date%.bak | ||
- | |||
- | msiexec /regserver | ||
- | regsvr32 /s wuapi.dll | ||
- | regsvr32 /s wuaueng1.dll | ||
- | regsvr32 /s wuaueng.dll | ||
- | regsvr32 /s wucltui.dll | ||
- | regsvr32 /s wups2.dll | ||
- | regsvr32 /s wups.dll | ||
- | regsvr32 /s wuweb.dll | ||
- | |||
- | net start wuauserv | ||
- | |||
- | |||
- | </ | ||
- | |||
- | ===== update.ins ===== | ||
- | |||
- | |||
- | <code winst> | ||
- | |||
- | [Actions] | ||
- | DefVar $NTVersion$ | ||
- | DefVar $ExitCode$ | ||
- | DefVar $WuAuVer$ | ||
- | DefVar $CurrentWsusUrl$ | ||
- | DefVar $WsusUrl$ | ||
- | DefVar $TargetGroup$ | ||
- | DefVar $CurrentTargetGroup$ | ||
- | DefVar $NeedReboot$ | ||
- | DefVar $ResultsFile$ | ||
- | DefVar $FoundCount$ | ||
- | DefVar $DownloadCount$ | ||
- | DefVar $NewDownloadCount$ | ||
- | DefVar $InstallCount$ | ||
- | DefVar $LogDir$ | ||
- | DefStringList $Results$ | ||
- | DefVar $winDomain$ | ||
- | DefVar $SystemType$ | ||
- | ; | ||
- | Set $LogDir$ = " | ||
- | ; | ||
- | Set $WsusUrl$ = GetProductProperty(" | ||
- | sub_get_winDomain | ||
- | Set $TargetGroup$ = GetProductProperty(" | ||
- | If ($TargetGroup$ = "" | ||
- | set $TargetGroup$ = $winDomain$ | ||
- | Endif | ||
- | Set $SystemType$ = GetSystemType | ||
- | ; | ||
- | set $NeedReboot$ = " | ||
- | set $InstallCount$ = " | ||
- | ; | ||
- | |||
- | ShowBitmap " | ||
- | |||
- | Set $NTVersion$ = GetNTVersion | ||
- | |||
- | Set $CurrentWsusUrl$ = GetRegistryStringValue(" | ||
- | |||
- | ; Surprisingly GetRegistryStringValue will also read DWORD values from the | ||
- | ; registry and convert them to decimal strings: | ||
- | If GetRegistryStringValue(" | ||
- | Set $CurrentTargetGroup$ = GetRegistryStringValue(" | ||
- | Else | ||
- | Set $CurrentTargetGroup$ = "" | ||
- | Endif | ||
- | |||
- | if not ( ($CurrentWsusUrl$ = $WsusUrl$) and ($CurrentTargetGroup$ = $TargetGroup$) ) | ||
- | Message " | ||
- | dosinanicon_stop_wuauserv | ||
- | registry_wsus_passive | ||
- | if not ( $TargetGroup$ = "" | ||
- | registry_wsus_targetgroup | ||
- | endif | ||
- | dosinanicon_start_wuauserv | ||
- | endif | ||
- | |||
- | |||
- | dosinanicon_check_wuauserv | ||
- | |||
- | If FileExists($LogDir$ + " | ||
- | LogError " | ||
- | isFatalError | ||
- | Else | ||
- | |||
- | Set $ResultsFile$ = $LogDir$ + " | ||
- | | ||
- | Message " | ||
- | execwithvbs_count_updates " | ||
- | Set $Results$ = loadTextFile($ResultsFile$) | ||
- | Set $FoundCount$ = getValue(" | ||
- | Set $DownloadCount$ = getValue(" | ||
- | Set $NewDownloadCount$ = getValue(" | ||
- | | ||
- | If not ($FoundCount$ = " | ||
- | If not ($NewDownloadCount$ = " | ||
- | Message $NewDownloadCount$ + "/" | ||
- | execwithvbs_download_updates " | ||
- | Set $Results$ = loadTextFile($ResultsFile$) | ||
- | Set $FoundCount$ = getValue(" | ||
- | Set $DownloadCount$ = getValue(" | ||
- | Set $NewDownloadCount$ = getValue(" | ||
- | Endif | ||
- | Message $DownloadCount$ + "/" | ||
- | | ||
- | If ( $NTVersion$ = " | ||
- | dosinanicon_stop_uphclean | ||
- | Endif | ||
- | |||
- | execwithvbs_install_updates " | ||
- | Set $Results$ = loadTextFile($ResultsFile$) | ||
- | Set $FoundCount$ = getValue(" | ||
- | Set $InstallCount$ = getValue(" | ||
- | Set $NeedReboot$ = getValue(" | ||
- | | ||
- | If ( $NTVersion$ = " | ||
- | dosinanicon_start_uphclean | ||
- | Endif | ||
- | | ||
- | Message $InstallCount$ + " von " + $FoundCount$ + " Updates installiert..." | ||
- | |||
- | Endif | ||
- | | ||
- | If ($NeedReboot$ = " | ||
- | if not (GetRegistryStringValue32(" | ||
- | LogError " | ||
- | Registry_MarkReboot_Error | ||
- | exitWindows / | ||
- | else | ||
- | Registry_UnMarkReboot | ||
- | LogError " | ||
- | isFatalError | ||
- | endif | ||
- | Else | ||
- | Registry_UnMarkReboot | ||
- | If ($NeedReboot$ = " | ||
- | comment " | ||
- | Registry_MarkReboot | ||
- | exitWindows / | ||
- | endif | ||
- | |||
- | If not (GetRegistryStringValue(" | ||
- | dosinanicon_stop_wuauserv | ||
- | registry_wsus_active | ||
- | dosinanicon_start_wuauserv | ||
- | Endif | ||
- | |||
- | if ($NTVersion$ = " | ||
- | dosinanicon_scrap_uninstdirs_xp | ||
- | endif | ||
- | |||
- | If ($SystemType$=" | ||
- | execwith_rescan " | ||
- | Else | ||
- | execwith_rescan " | ||
- | Endif | ||
- | SleepSeconds 5 | ||
- | If Not ($InstallCount$=" | ||
- | | ||
- | | ||
- | Endif | ||
- | Endif | ||
- | Endif | ||
- | |||
- | [Registry_MarkReboot] | ||
- | OpenKey [HKEY_LOCAL_MACHINE\Software\HRZMR] | ||
- | Set " | ||
- | |||
- | [Registry_MarkReboot_Error] | ||
- | OpenKey [HKEY_LOCAL_MACHINE\Software\HRZMR] | ||
- | Set " | ||
- | |||
- | [Registry_UnmarkReboot] | ||
- | OpenKey [HKEY_LOCAL_MACHINE\Software\HRZMR] | ||
- | DeleteVar " | ||
- | |||
- | [registry_wsus_passive] | ||
- | openkey [HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate] | ||
- | set " | ||
- | set " | ||
- | set " | ||
- | set " | ||
- | set " | ||
- | openkey [HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU] | ||
- | set " | ||
- | set " | ||
- | set " | ||
- | set " | ||
- | set " | ||
- | set " | ||
- | set " | ||
- | set " | ||
- | set " | ||
- | set " | ||
- | set " | ||
- | set " | ||
- | set " | ||
- | set " | ||
- | set " | ||
- | set " | ||
- | set " | ||
- | set " | ||
- | |||
- | [registry_wsus_targetgroup] | ||
- | openkey [HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate] | ||
- | set " | ||
- | set " | ||
- | |||
- | [registry_wsus_active] | ||
- | openkey [HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU] | ||
- | set " | ||
- | |||
- | [dosinanicon_stop_wuauserv] | ||
- | net stop wuauserv | ||
- | |||
- | [dosinanicon_start_wuauserv] | ||
- | net start wuauserv | ||
- | |||
- | [dosinanicon_check_wuauserv] | ||
- | sc query wuauserv|find " | ||
- | if errorlevel 1 goto REPAIR | ||
- | goto DONE | ||
- | :REPAIR | ||
- | regsvr32 /s wuapi.dll | ||
- | regsvr32 /s wuaueng1.dll | ||
- | regsvr32 /s wuaueng.dll | ||
- | regsvr32 /s wucltui.dll | ||
- | regsvr32 /s wups2.dll | ||
- | regsvr32 /s wups.dll | ||
- | regsvr32 /s wuweb.dll | ||
- | |||
- | net start wuauserv | ||
- | sc query wuauserv|find " | ||
- | if errorlevel 1 goto FAIL | ||
- | |||
- | :DONE | ||
- | del $LogDir$\wuauservnotrunning | ||
- | goto END | ||
- | :FAIL | ||
- | copy NUL $LogDir$\wuauservnotrunning | ||
- | :END | ||
- | [dosinanicon_stop_uphclean] | ||
- | net stop uphclean | ||
- | |||
- | [dosinanicon_start_uphclean] | ||
- | net start uphclean | ||
- | |||
- | [execwith_rescan] | ||
- | wuauclt.exe /detectnow | ||
- | wuauclt.exe /reportnow | ||
- | |||
- | [dosinanicon_scrap_uninstdirs_xp] | ||
- | setlocal | ||
- | cd /d %windir% | ||
- | attrib -h $NtUn* /d /s | ||
- | for /d %%d in ($NtUn*) do rmdir /s /q %%d | ||
- | endlocal | ||
- | |||
- | |||
- | [execwithvbs_count_updates] | ||
- | rem This is derived from: | ||
- | rem | ||
- | rem " | ||
- | On Error Resume Next | ||
- | |||
- | dim fso : Set fso = CreateObject(" | ||
- | |||
- | dim Results: Set Results = fso.CreateTextFile(" | ||
- | rem Results will contain return values to be read into a String List | ||
- | |||
- | Set wuS = CreateObject(" | ||
- | |||
- | Set updateSearcher = wuS.CreateupdateSearcher() | ||
- | Set searchResult = updateSearcher.Search(" | ||
- | |||
- | downloaded=0 | ||
- | downloadneeded=0 | ||
- | found = searchResult.Updates.Count | ||
- | |||
- | For I = 0 To found-1 | ||
- | Set update = searchResult.Updates.Item(I) | ||
- | If update.IsDownloaded = true Then | ||
- | downloaded = downloaded + 1 | ||
- | Else | ||
- | downloadneeded = downloadneeded + 1 | ||
- | End If | ||
- | Next | ||
- | |||
- | Results.WriteLine " | ||
- | Results.WriteLine " | ||
- | Results.WriteLine " | ||
- | Results.Close | ||
- | WScript.Quit | ||
- | |||
- | [execwithvbs_download_updates] | ||
- | rem This is derived from: | ||
- | rem | ||
- | rem " | ||
- | On Error Resume Next | ||
- | |||
- | dim fso : Set fso = CreateObject(" | ||
- | |||
- | dim Results: Set Results = fso.CreateTextFile(" | ||
- | rem Results will contain return values to be read into a String List | ||
- | |||
- | Set wuS = CreateObject(" | ||
- | |||
- | Set updateSearcher = wuS.CreateupdateSearcher() | ||
- | Set searchResult = updateSearcher.Search(" | ||
- | |||
- | found = searchResult.Updates.Count | ||
- | |||
- | Set updatesToDownload = CreateObject(" | ||
- | |||
- | olddownloads=0 | ||
- | |||
- | For I = 0 To found-1 | ||
- | Set update = searchResult.Updates.Item(I) | ||
- | If update.IsDownloaded = true Then | ||
- | olddownloads = olddownloads + 1 | ||
- | Else | ||
- | updatesToDownload.Add(update) | ||
- | End If | ||
- | Next | ||
- | |||
- | Set downloader = wuS.CreateUpdateDownloader() | ||
- | downloader.Updates = updatesToDownload | ||
- | downloader.Download() | ||
- | |||
- | downloaded = 0 | ||
- | For I = 0 To found-1 | ||
- | set update = searchResult.Updates.Item(I) | ||
- | If update.IsDownloaded = true Then | ||
- | | ||
- | End If | ||
- | Next | ||
- | |||
- | Results.WriteLine " | ||
- | Results.WriteLine " | ||
- | Results.WriteLine " | ||
- | |||
- | Results.Close | ||
- | WScript.Quit | ||
- | |||
- | [execwithvbs_install_updates] | ||
- | rem This is derived from: | ||
- | rem | ||
- | rem " | ||
- | On Error Resume Next | ||
- | |||
- | dim fso : Set fso = CreateObject(" | ||
- | |||
- | dim Results: Set Results = fso.CreateTextFile(" | ||
- | rem Results will contain return values to be read into a String List | ||
- | |||
- | Set wuS = CreateObject(" | ||
- | |||
- | Set updateSearcher = wuS.CreateupdateSearcher() | ||
- | Set searchResult = updateSearcher.Search(" | ||
- | |||
- | found = searchResult.Updates.Count | ||
- | |||
- | Set wuC = CreateObject(" | ||
- | |||
- | downloaded=0 | ||
- | For I = 0 To found-1 | ||
- | set update = searchResult.Updates.Item(I) | ||
- | If update.IsDownloaded = true Then | ||
- | | ||
- | | ||
- | End If | ||
- | Next | ||
- | |||
- | Set installer = wuS.CreateUpdateInstaller() | ||
- | installer.Updates = wuC | ||
- | Set installationResult = installer.Install() | ||
- | |||
- | installed = 0 | ||
- | For I = 0 to wuC.Count - 1 | ||
- | if installationResult.GetUpdateResult(I).ResultCode = 2 Then | ||
- | installed = installed + 1 | ||
- | end if | ||
- | Next | ||
- | |||
- | Results.WriteLine " | ||
- | Results.WriteLine " | ||
- | |||
- | |||
- | If installationResult.RebootRequired Then | ||
- | Results.WriteLine " | ||
- | Else | ||
- | Results.WriteLine " | ||
- | End If | ||
- | rem We need to do this as conversion of bools to text is localized, | ||
- | rem so we would sometimes get " | ||
- | |||
- | Results.Close | ||
- | WScript.Quit | ||
- | |||
- | [sub_get_winDomain] | ||
- | markErrorNumber | ||
- | opsiservicecall_authenticated | ||
- | if errorsOccuredSinceMark > 0 | ||
- | comment "nicht authentisiert" | ||
- | set $winDomain$ = "" | ||
- | else | ||
- | Set $Results$ = getReturnListFromSection(' | ||
- | set $winDomain$ = getValue(" | ||
- | endif | ||
- | |||
- | [opsiservicecall_authenticated] | ||
- | " | ||
- | " | ||
- | ] | ||
- | [opsiservicecall_getGeneralConfig_hash] | ||
- | " | ||
- | " | ||
- | " | ||
- | ] | ||
- | |||
- | |||
- | </ | ||
- | |||
- | --- // |