SMTP Port 25

Anything and Everything Related to Messaging and Collaboration, Active Directory and Scripting. It’s My Life!!!

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
About these ads

23 Responses to “Installing Patches/Application remotely on windows Machine using Psexec”

  1. ViJay said

    Nice one Krishna! that is one good idea for small companies cant get better

  2. Hey Thanks Vijay..

    Regards,
    Krishna

  3. 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/

  4. This is great Misha..

    Thank you very much.

    Regards,
    Krishna

  5. shahzad said

    I am trying to run this script from xp i m getting error on line 9 ,

  6. 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 :)

  7. 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

  8. saj said

    hi!

    its not working for me. it just copies the data and do nothing. I guess it searches for hotfix.exe file.

  9. you need to keep hotfix in location C:\Hotfixes

  10. 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.

  11. What version of Windows do you have on a destination computer?

  12. Saj said

    Its window 7 Enterprise.

  13. Saj said

    I think the problem is here:
    “”C:\Hotfixes\”" /quite” . It cant find .

    I guess there is something else instead of

  14. 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.

  15. try to change cmd /c to CMD / K

    By doing this, the CMD console will stay opened, so maybe you will see more details.

  16. Saj said

    i think its a psexec problem but not sure. any suggestions?

  17. 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?

  18. Saj said

    Just stuck after copying. Is it because its a Sqlserver hotfix?

  19. dragon said

    I have also ran into the issue with the /accepteula since it requires user acceptance on psexec.exe

  20. 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

  21. 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

  22. 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

  23. 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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

Join 49 other followers

%d bloggers like this: