I know by using ShellExecute, we can execute the exe program. On the other hand, if we want to kill the program by programming code, how to do?
Printable View
I know by using ShellExecute, we can execute the exe program. On the other hand, if we want to kill the program by programming code, how to do?
Which process you want to kill?
Was that process created by you? That means if you have HANDLE to that process you can use TerminateProcess (NOT recommened!).
If you wish to terminate a Windows Application (that has window), you can use FindWindow[Ex] to find the window handle and then ask the process by sending WM_DESTROY message to the main window. If you already have HWND of the main window of the process you want to terminate, just send the WM_DESTROY message to it.
When you terminate using WM_DESTORY, the process is given a chance to save its data and state and may also ignore the termination request. From "Applications" tab of task manager, when you click "End Task" this method is used by TM.
When you issue "End Process" from "Processes" tab, TerminateProcess is issued.
Do you mean WM_CLOSE, instead of WM_DESTROY?
Ohh yes, my mistake... It is WM_CLOSE message.
Actually, I was confused with CloseWindow API, that does minimizes the window...
Sorry, i don't know how WM_CLOSE work. Actually, i am not gonna to close the present window. My meaning is, i have another program now running, for example "program1.exe". I want to kill it by another program "program2.exe" by push a button. But program2 still running. How to do?
Take a look at Message Sender. It is based upon the concept provied by Ajay Vijay.
How can I kill a process ?
Cheers
If u want to kill process just like Taskmanager EndTask then u can use the following set of APIs aswell.Quote:
My meaning is, i have another program now running, for example "program1.exe". I want to kill it by another program "program2.exe" by push a button. But program2 still running. How to do?
Hope this will helps u.Code:EnumProcesses
OpenProcess
EnumProcessModules
GetModuleBaseName
TerminateProcess