Uninstall a previously installed program using Windows Installer in an MSI created with InstallShield 11.5

PC Tips No Comments
InstallShield 11.5 provides an easy way to search the registry for a desired value

Oftentimes when creating a new installer, it is necessary to provide for the contingency of previously installed software that will need to be removed. This can be a previous version of the same software (although those modules should maintain the same unique IDs, making this extra procedure unnecessary) or it can be a piece of software that will conflict with the software you’re trying to install (i.e. an old anti-virus program). Either way, in order to effectively remove the software, you’re going to need to:

1) Search for the program’s existence, and
2) Run its UninstallString from the registry.

Thankfully, InstallShield provides a couple of easy ways to accomplish this. The first (ideal) way to run the other software’s uninstaller is to do a simple system search for the registry key UninstallString for the program you wish to remove. The advantage to this method is that the search is very specific–it only looks within a particular key–so you can easily do 100 of these searches in the course of an install. In order to create the appropriate Custom Action within your MSI in this manner, do the following:

1) In the ‘System Search’ screen, add a new search by right-clicking and choosing ‘Add…’ (or hit Ins).
2) Choose ‘File Path, as specified by a registry entry’ at the next screen.
3) For the Registry Root choose ‘HKEY_LOCAL_MACHINE’
4) For the Registry Path type ‘SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\**ProgramName**’ (in other words, to uninstall Macromedia Flash, type ‘SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Macromedia Shockwave Player’
5) Under the optional Registry Value field, type ‘UninstallString’
6) Pick a memorable name for your new file-path variable like FLASH8PATH, then choose the top option to only store it in the tables, not use it as an install condition (you will attach the custom action later).

Your System Search is now complete, and will look for the UninstallString for Flash Player, then store that value to the variable FLASH8PATH. If you wish, you can immediately use this variable to create Install Conditions for different Custom Actions, either as an exists/does not exist check that launches an .exe or something, or by using the actual path contained in the variable. To launch the uninstaller, create the following Custom Action:

Working Directory: SystemFolder
Filename & Command Line: FLASH8PATH
Return Processing: Synchronous (Ignores exit code)
In-Script Execution: Immediate Execution

NB: You need to schedule the Custom Action after the AppSearch action in the InstallExecute sequence, because that’s when the MSI checks the registry for the key…it will fail otherwise.

systemfolder, custom action, msi, windows installer, previously installed, anti-virus, installshield 11.5, installshield, search registry, registry, installer, appsearch, installexecute, .msi, uninstallstring, variable, install conditions, uninstaller


Killing a system process or service in an MSI with InstallShield 11.5

Musings No Comments
TASKKILL.EXE (artist rendition)

When creating installers, it’s often necessary to stop running processes before beginning the actual install. For example, while creating an install of McAfee’s VirusScan Enterprise 8.0i, I discovered I needed to kill about 10 different processes associated with the free trial of McAfee Security Center and Personal Firewall that’s been showing up on all the new Dell laptops being shipped to my work. The trial is seriously insidious, since declining the free 90-day offer and closing all the appropriate windows, andexiting from anything McAfee-like in the system tray does nothing to stop those processes. They just keep on going, unless you end them from the Task Manager.
Now, for the purposes of rolling out VirusScan Enterprise to over 1,000 computers in the course of a few days, it would be rather impractical to ask users with varying degrees of computer savvy to terminate processes in a designated order prior to installing VSE.
Now, InstallShield has the built-in ability to call VBscripts within a Windows Installer (MSI), and you can launch a batch file from the installer easily by calling cmd.exe, as described on this MacroVision support page.
However, I found the VBscript solution was limited in its scope, as the ability to terminate a process does not extend to services. In order to kill a service (or SYSTEM process), you need to write a separate VBscript to kill services, since the command to terminate a process in userland will not translate over.
As to the batch file approach, you need to install the file first, then run it, since you can’t stream it into the binary data, so it plays havoc with your installer if you need to terminate processes before you copy files.
After trying a few batch files launched from the command line, and meeting with varying degrees of failure (probably due to my ignorance of proper sequencing), it occurred to me that there was a really simple way around this mess: taskkill.
Taskkill, otherwise known as the command I was launching from the batch file I was copying over to the destination machine in a nested MSI, can be launched in InstallShield 11.5 quite easily. Basically, you point the Working Directory over to the [SystemFolder] in a Custom Action, where taskkill.exe lives on every Windows NT based system. Then, enter the following command line:

“[SystemFolder]taskkill.exe” /f /im (processname)

In other words, to kill notepad.exe, type:

“[SystemFolder]taskkill.exe” /f /im Notepad.exe

Remember to set the Custom Action to ‘Synchronous (Ignores exit code)’ to avoid erroring out because of a lack of response from taskkill.exe after it terminates the designated process. I suggest placing these actions immediately after the CostFinalize action in the Execute sequence of the standard install.
Using this method, I was able to easily kill all 10 processes running with McAfee’s free trial software, and toast the software itself by running its uninstaller. An elegant and simple solution, arrived at through truly miserable and misguided trial and error.

Installer, InstallShield 11.5, InstallShield, Custom Action, synchronous, exit code, process, processes, service, services, execute sequence, mcafee, virusscan, mcafee security center, mcafee personal firewall, costfinalize, taskkill, taskkill.exe, system process, system service, terminate process, kill a process, kill process, free trial, vbscript, batch file