All Forums >> [Scripting] >> Post a VBScript >> Strong Force Wsus - Client Update Wsus 3.0 Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
'*************************************************************************************************** 'Windows Update Force 'script Write by Jeferson Propheta '04/02/2007 ' 'Version History '- Change Service Type to Automatic - Create LOG '- WUAUSERV service Instrumentation WMI - Reset Client ID '- Re-Install WSUS AGENT '- Delete SoftwareDistribuition Folder - Check if Aready Ran Before '- Wsus 3 Implementation 'Last Update 06/06/2007 '***************************************************************************************************
If NOT objAready.FileExists(strPatchFile) Then objShell.run "net stop wuauserv",0 ,True Wscript.Sleep 3000 objShell.Run "%ComSpec% /C set computername >" & strPatchFile,0 ,True objShell.RegDelete ("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\AccountDomainSid") objShell.RegDelete ("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\SusClientId") End If
strComputer = "." Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colServices = objWMIService.ExecQuery ("SELECT * FROM Win32_Service WHERE Name = 'wuauserv'") ServiceError = 1 For Each objService in colServices ServiceError = 0 errReturnCode = objService.StopService() Next
If ServiceError = 1 then objShell.run "%ComSpec% /C start" & strWsusAgentFile,0 ,true objShell.Run "%ComSpec% /C date/t >>" & strAgPatchFile,0 ,True Wscript.Quit End IF
objShell.run "%ComSpec% /C rd /S /Q %SystemRoot%\SoftwareDistribution",0 strComputer = "." Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colServices = objWMIService.ExecQuery ("SELECT * FROM Win32_Service WHERE Name = 'wuauserv'") For Each objService in colServices errReturnCode = objService.StartService() Next
Set updateSession = CreateObject("Microsoft.Update.Session") Set updateSearcher = updateSession.CreateupdateSearcher() Set searchResult = updateSearcher.Search("IsInstalled=0 and Type='Software'")
For I = 0 To searchResult.Updates.Count-1 Set update = searchResult.Updates.Item(I) Next
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 On Error Resume Next downloader.Download()
For I = 0 To searchResult.Updates.Count-1 Set update = searchResult.Updates.Item(I) If update.IsDownloaded Then End If Next
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) End If Next
Set installer = updateSession.CreateUpdateInstaller() installer.Updates = updatesToInstall On Error Resume Next Set installationResult = installer.Install() objShell.run "wuauclt.exe /ResetAuthorization /DetectNow",0 objShell.run "wuauclt.exe /ReportNow",0 ServiceError = 0
objShell.Run "%ComSpec% /C set computername >" & strRunFile,0 ,True End If
Set objAready = Nothing Set objShell = Nothing Wscript.Quit
< Message edited by jeferson.propheta -- 8/30/2007 4:12:59 AM >