Close another application programatically

  • Thread starter Thread starter Ciobanu Ionut-Georgian via DotNetMonster.com
  • Start date Start date
C

Ciobanu Ionut-Georgian via DotNetMonster.com

I would like to close another application from my own with code. Suppose we
have started myApp and every 3 secs i check to see if Calc.exe (or
calculator) is started. If it is, i want to close it. How can i do this? I
would really appreciate. Thank you in advance.
 
The best way is to find the window handle of the application, e.g. using
FindWindow, and then send it a WM_CLOSE message which will allow the
application to shut down cleanly. If that fails, you could then terminate
the process but use that only as a last resort.
See the Win32Window code (or use the library) in the SDF for P/Invoking
FindWindow (www.opennetcf.org/sdf/)


Peter
 
Back
Top