Installing Patches/Application remotely on windows Machine using Psexec
Posted by Krishna - MVP on August 6, 2010
Installing pathes/Application on a remote computer is not a tough one when you have lots of Microsoft and third party application to do this for us.Chances that few companies still does not wanted to relay on software to install patches and Administrator manually installed this. You should ask this question to the Administrators who works on weekend installing patches manually, do you like this to do every weekend ? I am sure he will give you very dirty look for sure
Below is the small piece of code you may like to use it for installing pathces or any small application on various computer remotely.
Prerequisits
1. Download PSExec.exe from Microsoft.com (http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx) and copy to C:\Psexec.exe
2. Create C:\Hotfixes and dump the path here
3. Copy below code and save it as C:\patchinstall.vbs
4. Create C:\Servers.txt with list of servername
5. Rename with the appropriate name
6. Open command prompt type cscript C:\patchinstall.vbs
This code will copy the patch to all the remote computer mentioned in C:\Servers.txt under C:\Hotfixes and it uses psexec.exe to install the patch on the remote computer
Set objShell = CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
set filetxt = objFSO.OpenTextFile("C:\Servers.txt",1)
strPSExec = "C:\PSExec.exe"
rbcopy = "c:\Windows\System32\Robocopy.exe"
strPSExec = objFSO.GetFile(strPSExec).ShortPath
rbcopy = objFSO.GetFile(rbcopy).ShortPath
do Until filetxt.AtEndOfStream
strComputer = filetxt.Readline
strComputer = trim(strComputer)
strCmd = "cmd /C " & rbcopy & " C:\Hotfixes" & " \\" & strComputer & "\c$\Hotfixes"
wscript.echo strcmd
objShell.Run strCmd, 1, True
strCmd = "cmd /C " & strPSExec & " \\" & strComputer & " ""C:\Hotfixes\<Hotfixname.exe>"" /quite"
wscript.echo strcmd
objShell.Run strCmd, 1, True
Loop


ViJay said
Nice one Krishna! that is one good idea for small companies cant get better
Krishna - MVP said
Hey Thanks Vijay..
Regards,
Krishna
Misha said
Additional solution, that I’ve built years ago for myself. I called it “Free Deployment System”
http://www.curuit.com/free-deployment-system-2007111465/
Krishna - MVP said
This is great Misha..
Thank you very much.
Regards,
Krishna
shahzad said
I am trying to run this script from xp i m getting error on line 9 ,
Misha said
While ago i did something similar for myself
.
You can read about my solution here: http://www.curuit.com/free-deployment-system-2007111465/
it is pure Batch
Saj said
Its not working for me. It do copy the files in the specified directory on remote machine but nothing else. I cant see patch applied to the machine in window update history.
I really need this solution as i have to deploy many patches manually as WSUS is not doing the work.
Please help
saj said
hi!
its not working for me. it just copies the data and do nothing. I guess it searches for hotfix.exe file.
Krishna - MVP said
you need to keep hotfix in location C:\Hotfixes
Saj said
Hi Krishna!
Thanks for the reply. Yes the hotfix are in C:\Hotfixes both on source and destination computers.
Its works fine with copying but it cant execute the file.
Misha Hanin said
What version of Windows do you have on a destination computer?
Saj said
Its window 7 Enterprise.
Saj said
I think the problem is here:
“”C:\Hotfixes\”" /quite” . It cant find .
I guess there is something else instead of
Saj said
I entered file name direct:
strCmd = “cmd /C ” & strPSExec & ” \\” & strComputer & ” “”C:\Hotfixes\SQLServer2008R2-KB2494088-x64.exe”" /quite”
but even that didnt help. I can see in a flash screen that its says
The system cannot find the specified file.
ITstuff | CuruIT.com (@itstuff) said
try to change cmd /c to CMD / K
By doing this, the CMD console will stay opened, so maybe you will see more details.
Saj said
i think its a psexec problem but not sure. any suggestions?
Saj said
ok finally i manage to run it with manual way i.e inserting the file name instead of . The script copies the file and run for more than 1 min and i can see some message in new command prompt in a flash and thats it. I cant find the KB installed on the remote computer.
Any way i can print the error message on the screen or file?
Saj said
Just stuck after copying. Is it because its a Sqlserver hotfix?
dragon said
I have also ran into the issue with the /accepteula since it requires user acceptance on psexec.exe
NK said
You must edit the line in the script: “”C:\Hotfixes\”"
Change into your patch file name eg. “”C:\Hotfixes\KB999999.exe”"
Also, there’s a typo in the script. /quite must be fixed to /quiet
Carlos said
how would I install a list of patches from a folder that contains more than 20 patches to machines that few will need 5 patches other 8 and the rest 20 patches…. any input on this one… this is my dilemma that I have…. please help
Jon Snow said
There’s an app called Batchpatch that lets you automate this process. The free evaluation is good for up to 7 remote hosts at a time. Check it here: http://batchpatch.com
rav36 said
Hi Krishna,
i would want to install the patch but not to reboot the server, any additional lines should be added to the script?
Thank You