There are a lot of times when you need to silently uninstall an application from computers in your network that should not be installed. These are what I refer to as "unapproved applications". Yeah, I know... It's original, isn't it? At any rate, these applications need to be removed from one or more computers in your network. You did not install them and you do not have the installation source files. How can this be done efficiently without walking to each desk or staying late?
Almost every application these days has an uninstall string stored in the registry. This information is available in the registry and in plain text. Most of the time, the default uninstall string is based on prompting the computer user for questions like, "Are you sure you want to remove this product?" These questions are annoying from a system admin perspective, because you will most likely not be there to click on Yes, nor do you want to be there to click Yes. The uninstall strings can be slightly modified to suppress those questions and allow the software to be uninstalled silently or with just a progress bar.
Let's look and see where to find those elusive uninstall strings. The first place to start is in the "Add/Remove Programs" for Windows XP or "Programs and Features" for Windows Vista/7. Open your appropriate Control Panel item and find the application that needs to be removed. Document the exact name of the application. For exmple, if Adobe Reader X is the application to remove it is listed in my system as "Adobe Reader X (10.1.0)".
The next step will involve searching the registry. Now is the time for my disclaimer.
NOTE - Modifying the registry is dangerous. Any changes made as benign as they may appear can cause your system to become unstable or unusable. Proceed at your own risk. I am not responsible for any problems that may occur from you entering your registry.
Now that's out of the way, let's get down to business. To open the registry open a Run Command and type "regedit". From within the regsitry go to the following location based on your OS architecture.
- Windows XP/Vista/7 32-bit -
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
- Windows XP/Vista/7 64-bit with 32-bit software -
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall
- Windows XP/Vista/7 64-bit with 64-bit software -
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
Search the registry from the Uninstall folder for the exact information documented from the Add/Remove Programs or Programs and Features. You do not need to enable the Match Whole String Only check box.
Once you find the entry look for a string value labeled UninstallString. That value needs to be copied out to a text document for modification later. The example I have been using for this exercise is Adobe Reader X. This may not necessarily be a piece of software that gets uninstalled in your environment, but the concepts are still the same across the board in regards to MSI uninstalls.
The uninstall string for Adobe Reader X should look something like this when copied out of the registry - "MsiExec.exe /I{AC76BA86-7AD7-1033-7B44-AA1000000001}". We are going to write a script that will use this information to execute a completely silent uninstall of Adobe Reader X.
**********************************BEGIN SCRIPT**************************************
Set Local
REM Identify if the computer is 32-bit or 64-bit
IF NOT "%ProgramFiles(x86)%"=="" (goto ARP64) else (goto ARP86)
REM Operating system is X64. Check for Adobe Reader in emulated Wow6432 uninstall key
:ARP64
reg query HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432NODE\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-7AD7-1033-7B44-AA1000000001}
if NOT %errorlevel%==1 (goto End) else (goto RemoveAdobe)
REM Operating system is X86. Check for Adobe Reader
:ARP86
reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-7AD7-1033-7B44-AA1000000001}
if %errorlevel%==1 (goto RemoveAdobe) else (goto End)
REM If 1 returned, the product was not found. Run uninstall string here.
:RemoveAdobe
start /wait %windir%\system32\msiexec.exe MsiExec.exe /x{AC76BA86-7AD7-1033-7B44-AA1000000001} /qn
REM If 0 or other was returned, the product was found or another error occurred. Do nothing.
:End
End Local
*****************************************END SCRIPT***********************************
Note the change to the Uninstall String we copied from the registry. It was "MsiExec.exe /I{AC76BA86-7AD7-1033-7B44-AA1000000001}". It is now in the script as "MsiExec.exe /x{AC76BA86-7AD7-1033-7B44-AA1000000001} /qn". The reason for the change is due to the syntax required for msiexec.exe to do its magic. The script can be deployed through Group Policy as Logon or Logoff script.
Below is a list of common syntax usages and their meanings for msiexec.exe.
Installation Options
msiexec /i <MSI File Location> /qb
- This installs an MSI based application in quiet mode with a progress bar and a cancel button
msiexec /i <MSI File Location> /qb-
- This installs an MSI based application in quiet mode with a progress bar and without a cancel button
msiexec /i <MSI File Location> /qn
- This installs an MSI based application in quiet mode with no visible indication an application is being installed
Removal Options
msiexec /x <MSI File Location> /qb
- This removes an MSI based application in quiet mode with a progress bar and a cancel button
msiexec /x <MSI File Location> /qb-
- This removes an MSI based application in quiet mode with a progress bar and without a cancel button
msiexec /x <MSI File Location> /qn
- This removes an MSI based application in quiet mode with no visible indication an application is being installed
Logging can be enabled by adding a /l to the end of the the msiexec line followed by a location to store the log file.
Eample - msiexec /i <MSI File Location> /qn /l %temp%\MyApplicationLog.log
This example installs the application completely silent and creates a log file in my user profile's temp folder called MyApplicationLog.log. The user profile's temp folder is located in "C:\Documents and Settings\<userprofile>\Local Settings\Temp" for Windows XP or "C:\Users\<userprofile>\AppData\Local\Temp" for Windows 7.
Using this methodology you can uninstall almost any application on your network that uses the MSI Installer engine. If the application in question uses another type of engine you may need to search Google for a silent option for the application. Chances are you are not the first one to ask the question. Some ideas to keep in mind for those other engines usually use something like /s or /q, /silent, or even /verysilent.
Uninstallation of any application while network is a difficult process. Though as per your guidelines this is much easy but for a beginner this is not much easy. Further it consultant also provides the services to manage all these matters.
ReplyDeleteI accidentally deleted a comment from a reader. He was asking about an error regarding Expected Statement.
ReplyDeleteThe example should be used as a batch file with a BAT extension and not VBS.