Programmatically (From Xojo) Close an Application

Hello everyone.
I am building a “managing” application which I would like to start and stop some other applications (some Xojo, some other type) in windows. How can I programmatically quit / close an application in windows?

Thanks in advance for any help.

Aaron Ballman has posted an example using declares here: How to KILL/close another process from RB

on windows sending close message to the window may do it.

Thank you Ashot and Christian,

It seems that the simple shell command:

[code] dim myShell as Shell

myShell = new Shell
myshell.Execute “taskkill /F /IM Application.exe”[/code]

is doing the job, provided that it has Administrator privileges… I need to test it for the various versions of windows, but that will do it for me. Ashot you pointed me to the right direction (this was included in the post).

On windows not all systems have Taskkill (it is in installed by certain service packs). Don’t know if you’re application will be in public domain, but something to think about. Most businesses have taskkill removed from their systems or blocked to prevent malware from closing processes.

A sure definite way is Windows api… Get the process list using api, get the handle of the process from the list and feed it to
TERMINATEPROCESS (HANDLE, UINT)

see msdn.microsoft.com or use Google for mentioned api specifics.

Oops ashot covered this in aarons mentioned post.

[quote=86405:@Matthew Combatti]On windows not all systems have Taskkill (it is in installed by certain service packs). Don’t know if you’re application will be in public domain, but something to think about. Most businesses have taskkill removed from their systems or blocked to prevent malware from closing processes.

A sure definite way is Windows api… Get the process list using api, get the handle of the process from the list and feed it to
TERMINATEPROCESS (HANDLE, UINT)

see msdn.microsoft.com or use Google for mentioned api specifics.[/quote]

Thanks Matthew,

Does the TerminateProcess method work with all Windows versions?
Any way, it won’t be public domain. It will actually be quite controlled and it will be installed as the monitoring/managing application of a POS used in Restaurants and Coffee shops. It is meant to monitor the health of all the subsystems as well as starting and terminating helper applications and services.

Do you think there might be a problem with that? The minimum configuration (for older systems that we will take over) is Win XP and we can install any service pack we want if not already installed. As far as I checked Taskkill works on XP, 7 and 8…

Do you think that using the TerminateProcess with the Windows api is better?

TerminateProcess is in every windows system down to windows 3.1 (ancient). In general practice, APIs are never removed from an OS, rather only added to (for backwards compatibility). All of the mentioned apis in aaron ballermans post at forums.realsoftware.com will work perfectly. This would also be the “best practices” method (using api) since I imagine in the restaurant setting (any POS really) the systems should already have certain privileges blocked. Since using Shell would spawn a new process, which should be prevented in a POS for security reasons and customer safety. But using apis, no processes are spawned and your application can “speak” with the kernel directly telling it to terminate additional processes.

You say that you are expected to be able to use windows XP? You may already know, but just in case, you will want to compile with Xojo 2013 as XP is not supported in Xojo 2014. (Something to keep in mind). I would also mention to the resaurant that XP no longer being supported by Microsoft, or no longer issuing security updates, could open the possibility to intrusion (if connected to the web) and a possible future system upgrade may in fact be beneficial to them. :slight_smile:

[quote=86471:@Matthew Combatti]TerminateProcess is in every windows system down to windows 3.1 (ancient). In general practice, APIs are never removed from an OS, rather only added to (for backwards compatibility). All of the mentioned apis in aaron ballermans post at forums.realsoftware.com will work perfectly. This would also be the “best practices” method (using api) since I imagine in the restaurant setting (any POS really) the systems should already have certain privileges blocked. Since using Shell would spawn a new process, which should be prevented in a POS for security reasons and customer safety. But using apis, no processes are spawned and your application can “speak” with the kernel directly telling it to terminate additional processes.

You say that you are expected to be able to use windows XP? You may already know, but just in case, you will want to compile with Xojo 2013 as XP is not supported in Xojo 2014. (Something to keep in mind). I would also mention to the resaurant that XP no longer being supported by Microsoft, or no longer issuing security updates, could open the possibility to intrusion (if connected to the web) and a possible future system upgrade may in fact be beneficial to them. :-)[/quote]

Thank you Matthew,
I will go the API way using TerminateProcess. In Windows 8 (maybe also in 7) I need to run it as administrator though to be able to actually terminate the application.

[quote=86405:@Matthew Combatti]On windows not all systems have Taskkill (it is in installed by certain service packs). Don’t know if you’re application will be in public domain, but something to think about. Most businesses have taskkill removed from their systems or blocked to prevent malware from closing processes.

A sure definite way is Windows api… Get the process list using api, get the handle of the process from the list and feed it to
TERMINATEPROCESS (HANDLE, UINT)

see msdn.microsoft.com or use Google for mentioned api specifics.[/quote]

Taskkill has been there since XP, and that OS is not even supported anymore.

I’ve packaged applications for a variety of businesses of various sizes. I have never seen Taskkill removed.

Taskkill is just fine to use.