close a running application

  • Thread starter Thread starter carmen
  • Start date Start date
C

carmen

How could I close a running application? All that I find is the Process
object but not for the CompactFramework.
Thank you for your help!
 
The Process class is available in the SDF (www.opennetcf.org/sdf), but that
only helps if you spawned the process. If not, you must get an instance
handle for the process through P/Invoke.

<ctacke/>
 
For another windowed application you should first try to send a WM_CLOSE
message to the applications main window to allow the application to close
cleanly. If this fails you can use GetWindowThreadProcessId with the handle
(hwnd) for the window. You can determine this using FindWindow and the
form's caption. Alternatively you can use the Toolhelp APIs to get a
snapshot of all the running processes on the system to get the ID of the one
you want to terminate - the SDF has a managed implementation of Toolhelp.
You can then call OpenProcess with this ID to get a process handle and pass
this to the TerminateProcess API. You will also be able to use the
GetProcessById method in the SDF's Process class but there is a bug in the
current version's Kill method so this doesn't work.

Peter

--
Peter Foot
Windows Embedded MVP
www.inthehand.com | www.opennetcf.org

Do have an opinion on the effectiveness of Microsoft Windows Mobile and
Embedded newsgroups? Let us know!
https://www.windowsembeddedeval.com/community/newsgroups
 
Back
Top