miércoles, 2 de agosto de 2017

PSEXEC, Software remote installation

Getting bored of not having spare time for applying security updates at work, I thought about how to do it easier and faster and here you are the result.

Everyone knows there are some software which release security updates very often, so I made up some scripts for updating it in an unattended, silent and remote way.

They are the following; Adobe Reader, Chrome, Firefox, Flash Player y java.

And also windows updates, but that is a different story.

The command line tool we’re going to use is  PSEXEC.EXE  

PSEXEC is part of Microsoft Sysinternal  and it allows you to run processes in a remote machine.

Its syntax is as follow: psexec [\\computer[,computer2[,...] | @file\]\]\[-u user [-p psswd][-n s][-r servicename][-h][-l][-s|-e][-x][-i [session]][-c [-f|-v]][-w directory][-d][-<priority>][-a n,n,...] cmd [arguments]

Like actions will speak louder than words here you are some detailed explanations.

Most times we’re going to use the same psexec arguments and we only need to surfing the Internet in order to look for  how to install the software in a silent way from a command line terminal.

E.g. the next command would install  flashPlayer on  pc1 computer.

psexec \\pc1 -c -s -u dominio\username -p password \\path\flashplayer.exe -install -force

-c, copy the exe file from the path \\path\flashplayer.exe  to pc1
-s, run the process with system privileges
-u y -p, allow us set the username & password which we’ll user to log on to the remote machine. (obviously an admin account)

And flashplayer.exe -install -force, are the arguments to install FlashPlayer.





So far so good but, what’d happen  if we would need to set up the software on 100 machines.

Obviously, this way will be a little boring, so we’re going to improve our batch and we’ll set the 100 computers on one shot J

The process is quite simple; a loop will read the computer names from a file (computers.txt) executing the installation command line for each one. In addition to this, we set a couple of logs file to keep everything under control and voila! … a useful script that allows us to save an important amount of time.

Concerning the log files, the first one gives us the exit code of the process (log.txt) and the second one, the detail of what have happened just in case we have to do some debugging (detail_%MYDATE: =%.log).

Here you are an script example for Acrobat Reader,


And a running example with Java


Obviously, they are  better and faster   ways to do the same but this one doesn't  work so bad.

One last thing, it is advised to open the terminal we’ll use for run the script with an admin user.

And finally, we can use PSEXEC for install almost everything, running commands and so on.

Here you are the code 

Enjoy J
Culex.


No hay comentarios:

Publicar un comentario