Kill Helper App

Hey guys,

How does one go about killing a help app that has been launched from your own app? This is something that I am effectively hiding that is running in the background that the user does not see or interact with. I’ve used console helper apps in shells before and those kill when the shell is closed. But this app is a standalone GUI app that has a way to be hidden from the user. So I want to open it, do my operations with it and then kill it.

The app is a TFTP server app so once it is started and loads its INI file, there’s nothing that the user does to interact with it. Once the TFTP transfer is complete, I want to then kill the server app.

How can I do this?

Does the app know when the transfer is complete? If so why not have it self terminate?

How are you starting it ?
If its started via the shell its a child & it will go when the main app goes.
If you use “launch” then its not and you will require different privileges to kill it.

Or you can have the main app hold a mutex and the sub process tries to get it and as soon as it can it should quit (the main app is gone)
However this too can have issues if the main app should crash and leave the mutex behind

I’ve tried launching the app from a shell and when I try closing the shell, my app just hangs. Maybe I’m doing something wrong? Or do I need to close the whole app? If like to kill it when I am done with it. Is there a way to do it with elevated privileges? My app already uses UAC to enable administrator authentication and elevated privileges.

I can’t just have the app quit after the file transfer is complete. That would be great but it is not my app and it’s a server app so I don’t think that would be in the cards.

Not sure why it’d hang when you close the shell but its certainly plausible.
How are you starting it in the shell ? Using “open pathToApp” or something else ?
I just tried a quick app with an async shell running BBEdit but NOT using the Open command and I can close the shell & BBEdit quits right away.

If you have elevated privileges there’s always an API to kill another process (ranging from sudo kill to something using a declare)

The mutex may be simplest as its basically just a flag to the other app that it can check periodically.
As long as TryEnter returns False then the main app is holding the mutex and the TFTP server should stay running.
Once TryEnter succeeds the TFTP app should quit.
Could check it with a timer periodically once a second or something.

[quote=144052:@Norman Palardy]Not sure why it’d hang when you close the shell but its certainly plausible.
How are you starting it in the shell ? Using “open pathToApp” or something else ?
[/quote]

I just open the shell and then call:

Shell.Execute AppName

Well, basically that. I think I put a path in there as well. But you get the point.

Well, since we are in the Windows target forum, Sudo Kill doesn’t work in Windows. :slight_smile:

[quote]
The mutex may be simplest as its basically just a flag to the other app that it can check periodically.
As long as TryEnter returns False then the main app is holding the mutex and the TFTP server should stay running.
Once TryEnter succeeds the TFTP app should quit.
Could check it with a timer periodically once a second or something.[/quote]

Well, this app is a 3rd party app that I have no control over. It’s a finished product. I’ve contacted the author and he’s given me permission to distribute it with my app. But it’s basically something that is not something I can do anything about.

For windows, you can use a force taskkill if you know the name of the application or PID.

taskkill

[quote=144059:@Jon Ogden]I just open the shell and then call:

Shell.Execute AppName

Well, basically that. I think I put a path in there as well. But you get the point.
[/quote]
Sure - Just I don’t think that will create the shell as a child process in a way that when you close the main process it will die.

No you’re quite right it wouldn’t :stuck_out_tongue:
But there should be either a cmd line way task kill or one of the API’s from WFS should IF you have the process ID

[quote=144059:@Jon Ogden]
Well, this app is a 3rd party app that I have no control over. It’s a finished product. I’ve contacted the author and he’s given me permission to distribute it with my app. But it’s basically something that is not something I can do anything about.[/quote]
AH yeah then your choice is to start it get the PID & eventually kill it somehow
See WFS - Process Management ProcessInformationWFS.Terminate
What I don’t see there is a ready made function to start the app & report the PID to you so you know what process to kill later on
I’m sure there is a way with the Windows API for CreateProcess

[quote=144068:@Rich Hatfield]For windows, you can use a force taskkill if you know the name of the application or PID.

taskkill[/quote]
Sweet! Perfect.