Killing app process upon upgrade. - Advanced Installer Community

We’re moving our forums to a new platform.

You can still browse and search existing topics, but you can no longer create new topics or post replies.

For questions, technical issues, or feature requests, please don’t hesitate to contact our support team at support@advancedinstaller.com.

Thank you for your understanding!

stevefal
Posts: 119
Joined: Wed Sep 03, 2008 9:02 pm
Location: Washington USA
Contact: Website

Killing app process upon upgrade.

Upon upgrade of my app, I want to kill the process of the previous version is it's running. I also give no option but to run the app upon final "Finish" button click.

Is this still the recommended approach to that? : http://www.advancedinstaller.com/user-g ... ocess.html

In the following code from that page, the objname declaration and assignment (lines 3 and 10) seem pointless. Am I missing something?

~~~~~~~~~
Dim objWMIService, objProcess, colProcess
Dim strComputer
Dim objname
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
strProcessKill = "'AdvancedInstaller.exe'"

Set colProcess = objWMIService.ExecQuery("Select * from Win32_Process Where Name = " & strProcessKill)
For Each objProcess in colProcess
objname = objProcess.Name
If objProcess.Name = "AdvancedInstaller.exe" then
objProcess.Terminate()
End If
Next
~~~~~~~~~

Also, will this code kill the process only in the current session, or will it also kill the process if it is running in other sessions on the same machine?
stevefal
Posts: 119
Joined: Wed Sep 03, 2008 9:02 pm
Location: Washington USA
Contact: Website

Re: Killing app process upon upgrade.

I didn't realize how quick and easy it'd be to test .vbs code :)

The script seems to work without lines 3 and 10, as I supposed I'd expect. Please tell me if I am missing something.

It also appears to kill a process only in the current session. That is actually preferable, unless there was a way to kill *and restart* the app in other sessions.
Rockettree
Posts: 1
Joined: Fri Nov 07, 2008 12:09 am

Re: Killing app process upon upgrade.

Hi,

I am also trying to get this working, but for a 64bit installer. Seems to work for the 32bit version but the vbs script does nothing on 64bit vista

I guess it is to do with the line

Set colProcess = objWMIService.ExecQuery("Select * from Win32_Process Where Name = " & strProcessKill)

Should the 'Win32_Process' be changed to something else? I have tried 'Win64_Process' but that didn't work.

Cheers,
Richard
stevefal
Posts: 119
Joined: Wed Sep 03, 2008 9:02 pm
Location: Washington USA
Contact: Website

Re: Killing app process upon upgrade.

I've abandoned this approach because I want my app to gracefully exit rather than to be killed.

So I wrote a small exe that walks windows, and sends a WM_CLOSE to those whose window title matches an argument I provide in the command line.

I then attached that as a custom action instead of the .vbs

Now I only have to get it to run upstream enough: http://www.advancedinstaller.com/forums ... f=2&t=8339
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Killing app process upon upgrade.

Hi,
I am also trying to get this working, but for a 64bit installer. Seems to work for the 32bit version but the vbs script does nothing on 64bit vista
Please note that the sample custom action should also work on 64-bit systems. Most likely the custom action doesn't have enough privileges when it runs. Can you please try scheduling it as "Deferred with no impersonation" under "InstallExecuteSequence" -> "Begin"?
So I wrote a small exe that walks windows, and sends a WM_CLOSE to those whose window title matches an argument I provide in the command line.
Although this is a bit more complicated than the VBScript custom action, it is the recommended approach.

Regards.
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
stevefal
Posts: 119
Joined: Wed Sep 03, 2008 9:02 pm
Location: Washington USA
Contact: Website

Re: Killing app process upon upgrade.

I see that the latest version of AI has an action for killing a process. I gave it a try, but settled for my own utility nonetheless.

The AI action kills a process by brute force rather than sending a WM_CLOSE event to it's top-level window. The latter is cleaner because the app has a chance to clean up after itself.

For instance, the app I'm working on displays a systray icon. When you kill the process, the icon is left around until the user mouses over it, whereas if the app is Closed the icon is removed.

My utilities takes a command line argument for the title of a window, and sends WM_CLOSE to it.

Maybe a future version of AI could have something like that.
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Killing app process upon upgrade.

Hi,

I have added this improvement on our TODO list and it will be available in a future version. Thank you for your suggestion.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
stevefal
Posts: 119
Joined: Wed Sep 03, 2008 9:02 pm
Location: Washington USA
Contact: Website

Re: Killing app process upon upgrade.

For the benefit of others needing to do the same thing, it turns out that attaching a kill-process (or equivalent) action to the Uninstall event in AI will effectively close your app during both upgrade and uninstall sequences, since uninstall is performed behind the scenes when upgrading.

I had previously attached the kill-process to both Begin and Uninstall, thinking that the former was necessary for the upgrade scenario and the latter for the uninstall scenario.
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Killing app process upon upgrade.

Hi,

Please note that Windows Installer uses the condition of the custom action to determine if it runs or not. The sequence (under which standard action it is scheduled) is used to determine when in the install process the custom action is launched.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
stevefal
Posts: 119
Joined: Wed Sep 03, 2008 9:02 pm
Location: Washington USA
Contact: Website

Re: Killing app process upon upgrade.

I'm not sure if what you're saying is meant to imply a problem.

My goals are to stop my app both on full uninstall; and upon upgrade, before the installer attempts to remove/replace any files or registry entries.

I'm using he condition "REMOVE="ALL", and I'm scheduling under "Uninstall". Won't that accomplish both goals?
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Killing app process upon upgrade.

Hi,

Yes, using the condition you mentioned will make the custom action run every time the package is uninstalled. However, even if it's correct to use this standard action, it's not necessary to schedule the custom action under "Uninstall" (it can be scheduled earlier or later depending on your needs). I was trying to explain that the custom action runs during an uninstall because of the condition, not because it is scheduled under "Uninstall".

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
stevefal
Posts: 119
Joined: Wed Sep 03, 2008 9:02 pm
Location: Washington USA
Contact: Website

Re: Killing app process upon upgrade.

I see. So it's possible I could move the custom action earlier in the sequence, assuming that the standard action I choose actually runs in my scenarios.

I've checked MSDN to see if "Uninstall" is an appropriate action for me to use, but that action does not appear in their docs: http://msdn.microsoft.com/en-us/library ... S.85).aspx "Begin" is not shown either.

RemoveExistingProducts sounds right, but apparently does not run during uninstallation: http://msdn.microsoft.com/en-us/library ... S.85).aspx

Assuming I want to kill the app as early as possible after the user has committed to upgrading or uninstalling, is "Begin" appropriate for both scenarios?
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Killing app process upon upgrade.

Hi,

"Begin" and "Uninstall" (along with other standard actions) are specific only to Advanced Installer. We introduced them to help you manage the custom actions better (they are more suggestive than the Windows Installer standard actions).

Like I mentioned in my previous posts, the condition of the custom action determines if the custom action runs or not. The position in the sequence (under which standard action it is scheduled) is used only to determine at which point in the install or uninstall process the custom action will run. It doesn't matter if the parent standard action is executed or not, if the condition of the custom action is true, it will run.
Assuming I want to kill the app as early as possible after the user has committed to upgrading or uninstalling, is "Begin" appropriate for both scenarios?
Yes, "InstallExecuteSequence" -> "Begin" is a good place for the custom action.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
stevefal
Posts: 119
Joined: Wed Sep 03, 2008 9:02 pm
Location: Washington USA
Contact: Website

Re: Killing app process upon upgrade.

Helpful as always, thanks so much.
stevefal
Posts: 119
Joined: Wed Sep 03, 2008 9:02 pm
Location: Washington USA
Contact: Website

Re: Killing app process upon upgrade.

I tried moving my custom CloseApp action to "InstallExecuteSequence" -> "Begin", but with the 'Remove = "ALL"' condition, it does not execute in the upgrade case.

Return to “Common Problems”