DO Windows update with(out) MDT
deployment with MDT2012 / SCCM2012:
http://scriptimus.wordpress.com/2012/03/22/mdt-2012-automating-updates-in-lite-touch-deployments/
deployment with other tools:
add this into regedit:
|
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate] |
and run this in your deployment sequence:
| '========================================================================== ' ' MDT2012 Windows Update Task Sequence ' DATE : 24.01.2013 ' '========================================================================== On error Resume Next Class DummyClass Public Default Function DummyFunction() End Function End Class Dim gethomepath Dim gObjShell, gObjProgressUI, gObjFileSystem, strScriptPath, strCommand, strCurrentUpdate Dim gObjSearchResult, gObjUpdateSearcher, gObjUpdateSession, gObjUpdateCollection, gStrTmpDir Dim gStrWinDir, gStrToolsDir, objDownload, objInstall, gObjDummyDict, varScriptPath, gStrOrgName, gStrTSName Set gObjShell = CreateObject("WScript.Shell") Set gObjFileSystem = CreateObject("Scripting.FileSystemObject") Set gObjUpdateSession = CreateObject("Microsoft.Update.Session") Set gObjUpdateCollection = CreateObject("Microsoft.Update.UpdateColl") Set gObjProgressUI = CreateObject("Microsoft.SMS.TsProgressUI") set env = CreateObject("Microsoft.SMS.TSEnvironment") Set gObjDummyDict = CreateObject("Scripting.Dictionary") Call gObjDummyDict.Add("DummyFunction", New DummyClass) gethomepath = left(WScript.ScriptFullName,len(WScript.ScriptFullName)-len(WScript.ScriptName)-1) gStrOrgName = "<YOUR COMPAGNY>" gStrTSName = "Microsoft Windows Update" gStrWinDir = gObjShell.ExpandEnvironmentStrings("%windir%") gStrTmpDir = gObjShell.ExpandEnvironmentStrings("%temp%") if gObjFileSystem.FileExists("C:\MININT\Tools\X86\TsProgressUI.exe") then gStrToolsDir = "C:\MININT\Tools\X86" elseif gObjFileSystem.FileExists("C:\MININT\Tools\X64\TsProgressUI.exe") then gStrToolsDir = "C:\MININT\Tools\X64" elseif gObjFileSystem.FileExists("C:\MININT\Tools\amd64\TsProgressUI.exe") then gStrToolsDir = "C:\MININT\Tools\amd64" end if Set gObjUpdateDownloader = gObjUpdateSession.CreateUpdateDownloader() fncDebugLog "update.vbs::main", "CreateUpdateDownloader" & vbTab & "Result: " & err.description & "(" & err.number & ")" Set gObjUpdateInstaller = gObjUpdateSession.CreateUpdateInstaller() fncDebugLog "update.vbs::main", "CreateUpdateInstaller" & vbTab & "Result: " & err.description & "(" & err.number & ")" varScriptPath = split(WScript.ScriptFullName, "\") For x = 0 To ubound(varScriptPath) - 1 strScriptPath = strScriptPath & varScriptPath(x) & "\" Next fncDebugLog "update.vbs::main", "strScriptPath :" & strScriptPath & vbTab & "Result: " & err.description & "(" & err.number & ")" strCommand = gStrToolsDir & "\TsProgressUI.exe /Register" gObjShell.Run strCommand,0 ,1 fncDebugLog "update.vbs::main", "Run :" & strCommand & vbTab & "Result: " & err.description & "(" & err.number & ")" '## Call gObjProgressUI.ShowActionProgress(gStrOrgName, gStrTSName, gStrTSName, _ "Windows Update initialize ...", 1, 4, _ "Configure Windows Update ...", 3, 4) '## Call gObjProgressUI.ShowActionProgress(gStrOrgName, gStrTSName, gStrTSName, _ "Windows Update initialize ...", 1, 4, _ "Stopping Service ...", 3, 4) strCommand = "net stop wuauserv" gObjShell.Run strCommand,0 ,1 fncDebugLog "update.vbs::main", "Run :" & strCommand & vbTab & "Result: " & err.description & "(" & err.number & ")" '## Call gObjProgressUI.ShowActionProgress(gStrOrgName, gStrTSName, gStrTSName, _ "Windows Update initialize ...", 1, 4, _ "Starting Service ...", 4, 4) strCommand = "net start wuauserv" gObjShell.Run strCommand,0 ,1 fncDebugLog "update.vbs::main", "Run :" & strCommand & vbTab & "Result: " & err.description & "(" & err.number & ")" '## WScript.Sleep 500 Call gObjProgressUI.ShowActionProgress(gStrOrgName, gStrTSName, gStrTSName, _ "Windows Update search ...", 2, 4, _ "Checking for Updates ...", 0, 1) '## Set gObjUpdateSearcher = gObjUpdateSession.CreateupdateSearcher() fncDebugLog "update.vbs::main", "CreateupdateSearcher" & vbTab & "Result: " & err.description & "(" & err.number & ")" Set gObjSearchResult = gObjUpdateSearcher.Search("IsInstalled=0 and Type='Software'") fncDebugLog "update.vbs::main", "Search(IsInstalled=0 and Type=Software)" & vbTab & "Result: " & err.description & "(" & err.number & ")" fncDebugLog "update.vbs::main", "UpdateCount :" & gObjSearchResult.Updates.Count & vbTab & "Result: " & err.description & "(" & err.number & ")" Call gObjProgressUI.ShowActionProgress(gStrOrgName, gStrTSName, gStrTSName, _ "Windows Update search ...", 3, 4, _ "Checking for Updates ...", 1, 1) WScript.Sleep 500 If gObjSearchResult.Updates.Count < 1 Then fncDebugLog "update.vbs::main", "Abort : No Updates Found!" & vbTab & "Result: " & err.description & "(" & err.number & ")" Call gObjProgressUI.ShowActionProgress(gStrOrgName, gStrTSName, gStrTSName, _ "Windows Update finalize ...", 4, 4, _ "No Updates available !", 1, 1) WScript.Sleep 1000 Set gObjProgressUI = Nothing WScript.Quit Else gObjUpdateDownloader.Updates = gObjSearchResult.Updates gObjUpdateInstaller.Updates = gObjSearchResult.Updates Set objDownload = gObjUpdateDownloader.BeginDownload(gObjDummyDict.Item("DummyFunction"), _ gObjDummyDict.Item("DummyFunction"), _ vbNull) fncDebugLog "update.vbs::main", "BeginDownload" & vbTab & "Result: " & err.description & "(" & err.number & ")" '## Download Updates While Not objDownload.IsCompleted = True If strCurrentUpdate <> gObjUpdateDownloader.Updates.Item(objDownload.GetProgress.CurrentUpdateIndex).Title Then strCurrentUpdate = gObjUpdateDownloader.Updates.Item(objDownload.GetProgress.CurrentUpdateIndex).Title fncDebugLog "update.vbs::main", "Download :" & strCurrentUpdate & vbTab & "Result: " & err.description & "(" & err.number & ")" End If Call gObjProgressUI.ShowActionProgress(gStrOrgName, _ gStrTSName, _ "", _ "Windows Update download (" & (objDownload.GetProgress.CurrentUpdateIndex + 1) & " / " & objDownload.Updates.Count & ")", _ objDownload.GetProgress.CurrentUpdateIndex, _ objDownload.Updates.Count - 1, _ gObjUpdateDownloader.Updates.Item(objDownload.GetProgress.CurrentUpdateIndex).Title, _ objDownload.GetProgress.CurrentUpdatePercentComplete , _ 100) WScript.Sleep 100 Wend Set objDownload = Nothing '## Install Updates Set objInstall = gObjUpdateInstaller.BeginInstall(gObjDummyDict.Item("DummyFunction"), _ gObjDummyDict.Item("DummyFunction"), _ vbNull) fncDebugLog "update.vbs::main", "BeginInstall" & vbTab & "Result: " & err.description & "(" & err.number & ")" While Not objInstall.IsCompleted = True If strCurrentUpdate <> gObjUpdateInstaller.Updates.Item(objInstall.GetProgress.CurrentUpdateIndex).Title Then strCurrentUpdate = gObjUpdateInstaller.Updates.Item(objInstall.GetProgress.CurrentUpdateIndex).Title fncDebugLog "update.vbs::main", "Install :" & strCurrentUpdate & vbTab & "Result: " & err.description & "(" & err.number & ")" End If Call gObjProgressUI.ShowActionProgress(gStrOrgName, _ gStrTSName, _ "", _ "Windows Update install (" & (objInstall.GetProgress.CurrentUpdateIndex + 1) & " / " & objInstall.Updates.Count & ")", _ objInstall.GetProgress.CurrentUpdateIndex, _ objInstall.Updates.Count - 1, _ gObjUpdateInstaller.Updates.Item(objInstall.GetProgress.CurrentUpdateIndex).Title, _ objInstall.GetProgress.CurrentUpdatePercentComplete , _ 100) WScript.Sleep 250 Wend Set objInstall = Nothing if err.number = 0 then env("installwsusupdates") = "OK" else env("installwsusupdates") = err.description & "(" & err.number & ")" end if endlog("windows update sur serveur wsus terminé avec le code erreur de fin:" & vbTab & "Result: " & err.description & "(" & err.number & ")") End If Function fncDebugLog(strFunction, strMessage) Dim objLogFile Set objLogFile = gObjFileSystem.OpenTextFile(gStrTmpDir & "\mdt_wsus_ts.log", 8, 1) objLogFile.WriteLine now() & vbTab & strFunction & vbTab & strMessage objLogFile.Close Set objLogFile = Nothing End Function Function endlog(strMessage) Dim objLog2File Set objLog2File = gObjFileSystem.OpenTextFile(gStrTmpDir & "\mdt_wsus_ts_end.log", 8, 1) objLog2File.WriteLine now() & vbTab & strMessage objLog2File.Close Set objLog2File = Nothing End Function wscript.quit (err.number) |
do not forget to ignore script error!
that’s all folk
/image%2F0881799%2F20140610%2Fob_a8c7fe_logo2.jpg)
Commenter cet article