AppDeploy.com

 


kill a process before uninstall an app

Click here to associate this thread with a Package KB article.
Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [AppDeploy Forums] >> Package Development >> kill a process before uninstall an app Page: [1]
Login
Message << Older Topic   Newer Topic >>
kill a process before uninstall an app - 11/22/2009 5:18:40 PM   
blade2

 

Posts: 31
Score: 0
Joined: 3/27/2008
Status: offline
Any tips on how to do this? I did not create the MSI, and it wont uninstal unless a process is killed first.
Post #: 1
RE: kill a process before uninstall an app - 11/23/2009 3:15:36 AM   
VBScab


Posts: 6657
Score: 188
Joined: 9/5/2006
From: London, UK
Status: online
You need to add a Custom Action, conditioned to run only during an uninstall (REMOVE~="ALL"). You'll find your best option is a VBScript-driven CA, as there are a quadzillion examples of scripts around which kill processes. Make sure, however, that any script you use is properly error-trapped.

_____________________________

- Don't know why 'x' happened? Want to know why 'y' happened? ProcMon will tell you.
- Try using http://www.google.com before posting.
- I answer questions only via forums. PMs and personal emails will be ignored.

(in reply to blade2)
Post #: 2
RE: kill a process before uninstall an app - 11/23/2009 4:19:55 PM   
airwolf


Posts: 565
Score: 3
Joined: 7/13/2009
From: teh interwebs
Status: offline
You could also write a simple AutoIT script to detect and kill the process before it runs the installer.

_____________________________

Andy Flesner, MCSA - Flesner.com
author.programmer.serveradmin.gamer

Follow Me on Twitter

(in reply to VBScab)
Post #: 3
RE: kill a process before uninstall an app - 11/23/2009 5:05:40 PM   
blade2

 

Posts: 31
Score: 0
Joined: 3/27/2008
Status: offline
Cheers thanks. I know if I want a custom action at install time where I did not create the msi, I call it with a transform, I can't call a transform at uninstall?

(in reply to VBScab)
Post #: 4
RE: kill a process before uninstall an app - 11/23/2009 11:00:53 PM   
PackageExpert

 

Posts: 122
Score: 3
Joined: 5/20/2008
From: Malaysia
Status: offline
If you have a vendor MSI then you should create a transform and add the custom action to Kill Process in the transform. As VBScab mentioned it should be set with condition REMOVE~="ALL" which will run during uninstall.

I usually sequence if before AppSearch with a Execution Property set to Synchronous and Execution Option set to Immediate.

(in reply to blade2)
Post #: 5
RE: kill a process before uninstall an app - 11/24/2009 1:46:33 AM   
shakeela511

 

Posts: 2
Score: 0
Joined: 8/1/2009
Status: offline
Hi,
Before uninstallation check the application is running
TASKLIST | FINDSTR  /I "application.exe"
if the application is running , kill the application and uninstall.. I hope it will help you

(in reply to PackageExpert)
Post #: 6
RE: kill a process before uninstall an app - 11/24/2009 3:00:05 AM   
blade2

 

Posts: 31
Score: 0
Joined: 3/27/2008
Status: offline
ok cheers, now I get it. sorry a bit fuzzy on VBSCAB's reply.

Thanks

(in reply to PackageExpert)
Post #: 7
RE: kill a process before uninstall an app - 11/24/2009 3:08:09 AM   
VBScab


Posts: 6657
Score: 188
Joined: 9/5/2006
From: London, UK
Status: online
quote:

TASKLIST | FINDSTR /I "application.exe"
Too messy. Most of the process-killing scripts around use the WMI object to enumerate the process list and, when the target process is found, get its process ID, using that to terminate the process. Avoid those scripts which kill named processes: always use the process ID. You can hopefully work out why.


_____________________________

- Don't know why 'x' happened? Want to know why 'y' happened? ProcMon will tell you.
- Try using http://www.google.com before posting.
- I answer questions only via forums. PMs and personal emails will be ignored.

(in reply to shakeela511)
Post #: 8
RE: kill a process before uninstall an app - 11/24/2009 11:43:54 PM   
shakeela511

 

Posts: 2
Score: 0
Joined: 8/1/2009
Status: offline
Hi VBScab,
If we kill the process , by process name, there is danger of termination of other processes related to the application also.
If we kill the process by using process id, which unique for the application, we can avoid above problem.
Thatswhy we cant use processnames to kill the application . Is it?

(in reply to VBScab)
Post #: 9
RE: kill a process before uninstall an app - 11/25/2009 3:51:19 AM   
VBScab


Posts: 6657
Score: 188
Joined: 9/5/2006
From: London, UK
Status: online
Exactly so.


_____________________________

- Don't know why 'x' happened? Want to know why 'y' happened? ProcMon will tell you.
- Try using http://www.google.com before posting.
- I answer questions only via forums. PMs and personal emails will be ignored.

(in reply to shakeela511)
Post #: 10
RE: kill a process before uninstall an app - 11/29/2009 5:33:10 PM   
blade2

 

Posts: 31
Score: 0
Joined: 3/27/2008
Status: offline
Thanks for your help guys. I have cracked it. I would have done as VBSCAB suggested however my process has a different PID each time it runs, so I don't see how I could.

(in reply to VBScab)
Post #: 11
RE: kill a process before uninstall an app - 11/29/2009 8:33:24 PM   
PackageExpert

 

Posts: 122
Score: 3
Joined: 5/20/2008
From: Malaysia
Status: offline
Then I guess you have no choice but to use the Process Name unless anyone else can come up with a better solution. Here's an example, just replace the exe..


On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
    ("SELECT * FROM Win32_Process WHERE Name = 'YourRunningApplication.exe'")
For Each objProcess in colProcessList
    objProcess.Terminate()
Next


Make sure that terminating this process has no linkage to the others as mentioned by VBScab and Shakeela511


_____________________________

You came here because google and your mates could't help you

(in reply to blade2)
Post #: 12
RE: kill a process before uninstall an app - 11/30/2009 3:45:54 AM   
VBScab


Posts: 6657
Score: 188
Joined: 9/5/2006
From: London, UK
Status: online
I changed my mind. My mind was on process creation, as I'm building a script at the moment which creates and monitors a process's execution. For that, I need the process ID, as there may be another instance (or instances) running.

For process termination, it wouldn't matter if there's more than one instance since, if you need to kill Fred.EXE in order to replace it, you would clearly need to kill all instances of it.


_____________________________

- Don't know why 'x' happened? Want to know why 'y' happened? ProcMon will tell you.
- Try using http://www.google.com before posting.
- I answer questions only via forums. PMs and personal emails will be ignored.

(in reply to blade2)
Post #: 13
RE: kill a process before uninstall an app - 11/30/2009 4:04:32 AM   
andys0123

 

Posts: 3
Score: 0
Joined: 5/20/2008
Status: offline
One way of killing the process is to download PStool from Sysinternals & create a Transform containing a Custom Action VBScript which uses PSList & PSKill. The script should call PSlist to list all the processes to a file, parse the file to find the relevant Process Name and thus its Proces ID, and then call PSKill to kill that process ID.
 
To call the uninstall using the new Transform, check out my comments in  http://www.appdeploy.com/messageboards/tm.asp?m=48858.

(in reply to VBScab)
Post #: 14
RE: kill a process before uninstall an app - 11/30/2009 4:23:40 AM   
VBScab


Posts: 6657
Score: 188
Joined: 9/5/2006
From: London, UK
Status: online
Without question, command line tools, especially ones of quality such as those from SysInternals, work. However, they are more suited to one-off - what I call QAD (Quick And Dirty) - usage. For a more professional approach, script is the way to go, since to describe error-trapping and conditional branching in batch/command files as "primitive" would be more than kind.


_____________________________

- Don't know why 'x' happened? Want to know why 'y' happened? ProcMon will tell you.
- Try using http://www.google.com before posting.
- I answer questions only via forums. PMs and personal emails will be ignored.

(in reply to andys0123)
Post #: 15
RE: kill a process before uninstall an app - 11/30/2009 4:47:05 AM   
andys0123

 

Posts: 3
Score: 0
Joined: 5/20/2008
Status: offline
Hence the VBScript just shelling out to run PSList & PSKill - not running from a batch file. Not an ideal solution, but it works exactly a required.

(in reply to VBScab)
Post #: 16
RE: kill a process before uninstall an app - 11/30/2009 8:44:52 AM   
AngelD

 

Posts: 2937
Score: 102
Joined: 6/9/2004
From: Sweden
Status: offline
If the process (file) is installed by the package then I would also (before executing the kill) get the path of the file and use that in the wmi query to make sure the process is part of the package and not any "random" process.

(in reply to blade2)
Post #: 17
Page:   [1]
All Forums >> [AppDeploy Forums] >> Package Development >> kill a process before uninstall an app Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI

0.078