Sometimes you want to deploy more that one Windows 7 hotfix with Configuration Manager. The hotfixes for Windows 7 is .MSU files and are installed using Wusa.exe.
If you wan to make the hotfix installation silent you simply add /quiet /norestart on the command line aswell.
Example command line: Wusa.exe c:\temp\Windows6.1-KB982018-v3-x64.msu /quiet /norestart
To simplify the installation I have made a small script the will parse all the files in the same directory as the script and install all files which ends with .MSU automatically. It can both be used to distribute the hotfixes using software distribution or in a Task Sequence so you can install the updates during OSD.
To use it simply save the script in the same folder as you Windows 7 hotfixes you want to deploy and then create a package and program with the folder as package source and the command line configured as below.
I strongly recommend that you allow configuration manager to restart the computer, otherwise the user can be prompted by the Windows Update agent to restart within 10 minutes.
If you need to troubleshoot it run it with allow user to interact, then you will see the updates being displayed in a command prompt.
Installmsu.vbs script:
Dim objfso, objShell
Dim folder, files, sFolder, folderidx, Iretval, return
Dim objfso, objShell
Dim folder, files, sFolder, folderidx, Iretval, return
Set objfso = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Wscript.Shell")
sFolder = left(WScript.ScriptFullName,(Len(WScript.ScriptFullName))-(len(WScript.ScriptName)))
Set folder = objfso.GetFolder(sFolder)
Set files = folder.Files
For each folderIdx In files
If Ucase(Right(folderIdx.name,3)) = "MSU" then
wscript.echo "wusa.exe " & sfolder & folderidx.name & " /quiet /norestart"
iretval=objShell.Run ("wusa.exe " & sfolder & folderidx.name & " /quiet /norestart", 1, True)
If (iRetVal = 0) or (iRetVal = 3010) then
wscript.echo folderidx.name & " Success"
Else
wscript.echo folderidx.name & " Failed"
wscript.quit(1)
End If
End If
Next
‘https://ccmexec.com/2012/02/installing-multiple-windows-7-hotfixes-msu-with-sccm/
‘http://www.insidethe.com/blog/2009/12/how-to-launch-a-wsh-vbscript-as-administrator-in-windows-7-and-vista/
mytitle=”MSU Installer”
mybuttons=65 ‘ vbOKCancel + vbInformation
If WScript.Arguments.Named.Exists(“elevated”) = False Then
‘Launch the script again as administrator
CreateObject(“Shell.Application”).ShellExecute “wscript.exe”, “””” & WScript.ScriptFullName & “”” /elevated”, “”, “runas”, 1
WScript.Quit
Else
‘Change the working directory from the system32 folder back to the script’s folder.
Set oShell = CreateObject(“WScript.Shell”)
oShell.CurrentDirectory = CreateObject(“Scripting.FileSystemObject”).GetParentFolderName(WScript.ScriptFullName)
MsgBox “Now running with elevated permissions”,0,mytitle
End If
Dim objfso, objShell
Dim folder, files, sFolder, folderidx, Iretval, return
Set objfso = CreateObject(“Scripting.FileSystemObject”)
Set objShell = CreateObject(“Wscript.Shell”)
sFolder = left(WScript.ScriptFullName,(Len(WScript.ScriptFullName))-(len(WScript.ScriptName)))
Set folder = objfso.GetFolder(sFolder)
Set files = folder.Files
something=0 ‘ there is nothing to do
For each folderIdx In files
If Ucase(Right(folderIdx.name,3)) = “MSU” then
something=1 ‘ there is something to do.
wscript.echo “wusa.exe ” & sfolder & folderidx.name & ” /quiet /norestart”
‘wscript.echo “wusa.exe ” & sfolder & folderidx.name
iretval=objShell.Run (“wusa.exe ” & sfolder & folderidx.name & ” /quiet /norestart”, 1, True)
‘iretval=objShell.Run (“wusa.exe ” & sfolder & folderidx.name, 1, True)
If (iRetVal = 0) or (iRetVal = 3010) then
‘wscript.echo folderidx.name & ” Success”
myprompt=folderidx.name & ” Success ” & “[” & iRetVal & “]”
Else
‘wscript.echo folderidx.name & ” Failed”
myprompt=folderidx.name & ” Failed ” & “[” & iRetVal & “]”
End If
devam=MsgBox(myprompt,mybuttons,mytitle)
If (devam = 2) or (devam = 3) or (devam = 7) Then
‘Cancel/Abort/No was clicked
wscript.quit(1)
End If
End If
Next
If (something = 0) Then
MsgBox “Nothing to do.”,64,mytitle
Else
MsgBox “Done.”,64,mytitle
restartla=MsgBox(“Close all programs and press Yes to restart or No to continue.”,36,mytitle)
If (restartla = 6) Then
Set WSHShell = WScript.CreateObject(“WScript.Shell”)
WshShell.Run “%SYSTEMROOT%\system32\shutdown.exe /r /t 0”
End If
End If
Thanks works like a charm 🙂
Hi,
I have one question regarding hotfixes. How do you detect if the hotfix was correctly installed? With programs, I can use queries and look in the “Add/Remove Programs” attribute class. But hotfixes are not in Add/Remove Programs… Do you know where the information is stored ?
Thanks,
Benoit
I am new to SCCM, scripts, everything. I need to deploy a list of .msu hotfixes to our company, and want to try your script. I feel really stupid asking, but do I need to alter it in any way (for example the names of the .msu’s, the server name, anything?)…
Hi,
No there is nothing you need to alter..
/Jörgen
Hi
May be I am doing it wrong… I copied your script from “Dim objfso, objShell” till the word “Next”, pasted it on a notepad and changed the name to Installmsu.vbs…. I kept all the .msu (I am trying to install IE 10 prerequisites) in one folder along with the Installmsu.vbs..Then I am using it with the command you mentioned above cscript Installmsu.vbs in the SCCM command line…but everytime it ends up with error code 1 in execmgr and installation fails. I tried it separately on my machine using just the command prompt, it fails… FYI, I am using download and run in my SCCM adverts. Please tell me what I am doing wrong…!!
Thanks in Advance…
Same problem here. Did you find the solution?
This script worked perfectly! Thank you so much for posting it!!!
Worked Perfectly 🙂 Thanks man!!
Thank you for the post. Only one question, why are you quitting the script when any .msu file installation is getting failed ? Removed the line :
wscript.quit(1)
and it’s working great. Thanks again.
Hi,
Because I wan’t to know if it fails so I can act on it. If you deploy updates where you know some will fail, just remove it as you just wrote.
/Jörgen
Not work for me
Hi Jorgen Nilssion
I have executed the script on client to was successful for 30 minitues. However, I deployed it to Client by package which was built on SCCM server while it still was running and no stopping as bellow command line in Process :
“c:\Windows\System32\wusa.exe” “C:\windows\ccmcache\k\Windows6.1-KB3161949-x64.msu /quiet /norestart”
Hi Jorgen Nilssion
I have executed the script on client to was successful for 30 minitues. However, I deployed it to Client by package which was built on SCCM server while it still was running and no stopping as bellow command line in Process :
“c:\Windows\System32\wusa.exe” “C:\windows\ccmcache\k\Windows6.1-KB3161949-x64.msu /quiet /norestart”
Please help me to solve the issue.
Thank for your support.
Quang Trieu
In the Deplymen type select “Script” installation and just run the cmd wusa.exe “Windows6.1-KB3161949-x64.msu” /quiet /norestart
In the “User Experience” set it for “Configuration Manager client will force a mandatory device restart”.
Even though you have used /norestart the SCCM will still wait for reboot prompt.
The problem that I had with this script is that when there is one previous KB already installed, this fails and the others on the folder will remain uninstalled. However by making some changes on the script from Daniel Classon, http://www.danielclasson.com/powershell-install-hotfixes-only-if-they-are-not-installed/, I got the problem solved.
$source = “.” #Source folder
$KBArrayList = @(“KB976373″,”KB980295”, “KB2481614”, “KB2494172”, “KB2736878”) #Patches that you need to install.
foreach ($KB in $KBArrayList) {
if ((Get-Hotfix -Id $KB -ea SilentlyContinue) -eq $Null) {
Start-Process -FilePath “wusa.exe” -ArgumentList “$source\$KB.msu /quiet /norestart” -Wait
}
}
This could be improved by importing a comma separated value file to create the array. Who would be the brave?…. 🙂