Hello Everyone and thanks for your help in advance. I have a third party program that is opened daily using Windows Scheduler, which in turn runs a process. However, at the end of the process, the program does not close itself instead simply terminating and leaving itself open. Because of this, Windows Scheduler fails on the next attempt to launch the program unless someone manually closes the program daily. I know a Windows form can launch an external exe, and assume it can also be used to close an external program or process, however, I do not know how to do this. Any insight on this topic would be greatly appreciated.

Closing an External Program
Bruce_Krasnof
MikeFrey
Thanks again for the help.
Lajash
In case you want to also start the program then you would need to use Process.Start() method and pass the .EXE with path.
Regards,
Vikram
Asifkhan75025
First of all, I feel you need to analyze why this particular program is terminating and not exiting correctly. If it is possible to make the application to gracefully exit, that would be a better approach. Try adding a Environment.Exit(0) explicitly in this program and see if it helps.
However, if this is what u need to do then: Here is a code snippet in C# that does it. You need to import the namespace System.Diagnostics. The sample terminates an instance of notepad if it is running.
Process
[] arrProcesses = Process.GetProcessesByName("notepad");if (arrProcesses.Length > 0)
arrProcesses[0].Kill();
Regards,
Vikram
Dvorak Pavel
Is there a graceful way to shut a program down besides CloseMainWindow The problem I have is one of the apps I'm dealing with minimizes itself to the system tray. I want to give it a chance to close gracefully, but CloseMainWindow does nothing since it doesn't really have a main window at the moment.
If there was a way to activate the program, it would open its main window then I could call CloseMainWindow. That would work most of the time, but some programs this app would be working with run strictly in the system try. (ie, no main window at all.)
Any suggestions