InstallShield Tips and Techniques

February 18, 2014

Kill-Process Custom Actions

Filed under: Reference Materials — shieldmaster @ 11:55 pm

When you have services or processes that are always running in the background, when you decide to uninstall the application you may be presented with this dialog box:


 

This dialog is created by the InstallShield engine after the “CostFinalize” Standard Action is completed.  It recognizes that a process is running that is slated for removal (could be a service or a actively running program) –so it attempts to get the issue resolved before it encounters a “File Locked” scenario.

I would rather kill the running process than allow this dialog box to hang up the installation – plus it seems likely that there will be a customer call to the support center, and that could be bothersome.

 

Option #1: Using the new Kill-Process Custom Action

 

If you are using InstallShield 2012 Spring (or later), they introduced a new Custom Action – the “Kill Process” – as shown here:

 

Here is the help topic on the Kill Process. To summarize:

  • Create a new Custom Action “ISI_KillProcess” – or in my sample “ISI_KillMAP”
  • Sequence it correctly – I wanted it quite early in the sequencing, plus I wanted to run it when the customer ran it silently (without UI Sequence)
  • Create a new MSI Property “ISTerminateProcesses” that contains a list of the processes to kill (if multiple ones, such a previous release names), separate by semicolon (;)

 

 

 

Option #1: Building your own Kill-Process Custom Action

 

If you are using any previous versions of InstallShield 2011 (or earlier), you have to create your own Custom Action to “Kill a Process”. I had typically used an InstallScript Custom Action (scripts downloaded from InstallSite.org ) to check for running processes – but the script ran very slow – and if you are checking for quite a few older versions (such as when you perform a “Major Upgrade” it could take over 5 minutes.

I built this Kill Process Custom Action using the standard “New EXE – Path referencing a directory” – as shown here:

To summarize:

  • Create a new Custom Action “ISI_KillProcess”
  • Sequence it correctly – I wanted it quite early in the sequencing – but the InstallScript engine needs to resolve the working directory “WindowsFolder” – so you have to sequence it after “ResolveSource” in the UI Sequence – and “CostFinalize” in the Execute sequence
  • Select “WindowsFolder”
  • Enter the following “taskkill /F /IM XXXXXX” – where ‘/F’ means to force the kill, ‘/IM’ is the option to provide the process name – and use the full process name (including the .EXE).

 

 

Hope this helps!

Shieldmaster

Advertisements

5 Comments »

  1. This will only work when running with the user’s administrator privileges (as opposed to Windows Installer’s privileges on non-impersonating deferred custom actions), meaning that it should be sequenced as an immediate custom action (not recommended since it modifies the system in-script), or as a deferred custom action with impersonization turned on.
    Both ways the installation must be started with administrator privileges – using a setup.exe with elevated privileges for example.

    Comment by Nir Bar — September 30, 2014 @ 1:28 pm

  2. Thanks a lot – was going crazy as to sequencing the Kill Process Costum Action. Done as shown in your screenshot and works like a charm!

    Comment by Simon — February 3, 2015 @ 10:12 am

  3. I know this is ancient history, but TaskKill.exe get’s an AccessDenied even when the installer is elevated to admin priviledges. This happened on Win7 with UAC turned on and also Windows 8. I find a better technique is to use FindWindow / SendMessage(WM_CLOSE). It is a soft close meaning that the application has to obey it without any user prompts (and a modal dialog will eat it as well). But it is better than an always failing with on TaskKill.exe

    I use Spy++ to get the classname of the top window. Then add the following InstallScript to my application.
    // Now Find and close the app
    nHwnd = FindWindow(“WindowsForms10.Window.8.app.0.3ce0bb8”, “”);
    if (nHwnd != 0) then
    SendMessage(nHwnd, WM_CLOSE, 0, 0);
    endif;

    Comment by MarkC — February 19, 2015 @ 1:16 pm

  4. Hi,
    I am using installsheidl 2012,I have used the implementation steps to run a process to be registered in th notification bar .
    The starting and removal of service working as expected while installation and uninstallation.
    But as i restart the system the process is getting unregistered getting no notification in the notification bar .

    Is there any way to start the process while restart .

    Regards
    kamlesh

    Comment by Kamlesh — October 27, 2015 @ 4:22 am

    • I am not aware of any – maybe other IS developers know?

      ShieldMaster

      Comment by shieldmaster — May 24, 2016 @ 10:28 pm


RSS feed for comments on this post. TrackBack URI

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 )

Google+ photo

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

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: