How to remotely remove software from a Computer (or batch of Computers) & install to another

Efstratios ArvanitidisICT Manager - Fleet Division
CERTIFIED EXPERT
Published:
Updated:
Edited by: Andrew Leniart
This article will show you how you can remove software remotely with the use of PsTools, and how to remotely install another one.

The procedure below will remove an existing Adobe Acrobat Reader DC installation and will install Adobe Acrobat Reader DC along with its latest patch. The same procedure can be used for any other software.


Prerequisites:


  • Download a copy of Windows Sysinternals "PsTools" using this link (PSTools.zip) 
  • Or you can download the complete suite using this link (SysinternalsSuite.zip)
  • Some basic knowledge of batch file scripting


The steps that need to be followed (in brief) are shown below:

1. Identify the GUID of the software to be removed with the use of a PowerShell command
2. Identify the Process (name and/or ID) of the running instance of the software on the remote computer.
3. Create the batch file which will:
a) Use PsKill (part of PsTools) to remotely kill any process of the s/w that is running on the target PC prior the removal
b) Use PsExec (part of PsTools) to remotely remove the software based on its GUID
c) Use PsExec to remotely install the new software from a network share at the source PC executing the batch file from.
d) Use PsExec to remotely install the latest patch of the software

Step 1:

Use PowerShell to identify the GUID of the actual software that you want to remove.

Command:


get-wmiobject Win32_Product | Format-Table IdentifyingNumber, Name -AutoSize

Result:


As shown in the results of the PS command, Adobe Acrobat Reader DC has the following GUID: {AC76BA86-7AD7-1033-7B44-AC0F074E4100}

P.S. More on decoding the Adobe Acrobat Reader GUID can be found in the following article: Identifying Existing Installs

Step 2:

As we need to run the removal command with the s/w closed at the remote computer, we need first to close any instance of the s/w running. To kill the relevant processes we need to identify them first. By running the below command we will be able to identify if there is any process running at the remote PC starting with "Acro"


Command:

pslist \\remotePCname -u uname -p pwd Acro

Result:


Step 3:

At this step, we will build the batch file that will perform 4 consecutive actions as described above.

a. Kill any running instance of Acrobat Reader on the remote PC based on the Process name as found in step 2 above.


Command:

pskill -t \\remotePCname -u uname -p pwd AcroRd32

Result:


b. Remove the installed version of the software based on its GUID


Command:

psexec \\remotePCname -u uname -p pwd cmd /c "msiexec.exe /x {AC76BA86-7AD7-1033-7B44-AC0F074E4100} /quiet /norestart"

Result:
Successful execution should result in "error code 0"

c. Install the new software


Command:


psexec \\remotePCname -u uname -p pwd cmd /c "msiexec.exe /i "\\sourcePCname\share\AcroRead.msi" /quiet /norestart"

Result:
Successful execution should result in "error code 0"


d. Install latest patch of the new software


Command:

psexec \\remotePCname -u uname -p pwd cmd /c "msiexec.exe /p "\\sourcePCname\share\AcroRdrDCUpd1900820081.msp" /quiet /norestart"

Result:
Successful execution should result in "error code 0"

The complete batch file would look like this:


pskill -t \\remotePCname -u uname -p pwd AcroRd32
psexec \\remotePCname -u uname -p pwd cmd /c "msiexec.exe /x {AC76BA86-7AD7-1033-7B44-AC0F074E4100} /quiet /norestart"
psexec \\remotePCname -u uname -p pwd cmd /c "msiexec.exe /i "\\sourcePCname\share\AcroRead.msi" /quiet /norestart"
psexec \\remotePCname -u uname -p pwd cmd /c "msiexec.exe /p "\\sourcePCname\share\AcroRdrDCUpd1900820081.msp" /quiet /norestart"


In case the above should be executed towards a batch of computers you can edit your batch file adding a loop towards the content of a file named computers.txt in which each line will include the name of each of the remote computers.

e.g. Create a file named computers.txt. Place the name of the remote PCs one per line as per example the example shown below. Save the file in the same folder with the batch file.

remotePCname1
remotePCname2
remotePCname3
.
.
.
remotePCnameN

The batch file should be like the following:

for /F %%i in (computers.txt) do (
pskill -t \\%%i -u uname -p pwd AcroRd32
psexec \\%%i -u uname -p pwd cmd /c "msiexec.exe /x {AC76BA86-7AD7-1033-7B44-AC0F074E4100} /quiet /norestart"
psexec \\%%i -u uname -p pwd cmd /c "msiexec.exe /i "\\sourcePCname\share\AcroRead.msi" /quiet /norestart"
psexec \\%%i -u uname -p pwd cmd /c "msiexec.exe /p "\\sourcePCname\share\AcroRdrDCUpd1900820081.msp" /quiet /norestart"
)

Notes:


  • The batch should be executed with elevated permissions
  • The uname & pwd are variables indicating the username & password of a user with administrative access on the remote PC. In the case of a Domain uname = domainname\username
  • You can add the folder with PsTools in your PATH environment variable, so that you can execute the commands from whichever location in your command prompt
  • PsTools are fully documented. You can check all the switches used by typing e.g. psexec /?
  • msiexec is fully documented. You can check all the switched used by typing msiexec /?


Hope you enjoy it and you found it helpful.



0
1,223 Views
Efstratios ArvanitidisICT Manager - Fleet Division
CERTIFIED EXPERT

Comments (0)

Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.

Get access with a 7-day free trial.
You Belong in the World's Smartest IT Community