Terminating Process [modified]
-
Hello all.. I'm making an application which terminate other processes in different way, i.e using TerminateProcess, WM_CLOSE, WM_QUIT, SC_CLOSE. Now i'm able to terminate process in all the way, But i need bit explanation in WM_CLOSE, WM_QUIT and SC_CLOSE.. How exactly it closes other process?? I believe there are two conditions which need to be fulfilled. 1> The target process has at least one window. 2> The target process doesn't handle the WM_CLOSE, WM_QUIT, SC_CLOSE message. So i'm doing this to enumerates all top level windows, In LPARAM i'm passing the pid of the target process..
EnumWindows((WNDENUMPROC)Enum_Terminate_Process, (LPARAM) aiPID[i]);
And in Enum_Terminate_Process, I'm doing something like this..
BOOL CALLBACK Enum_Terminate_Process(HWND hWnd, LPARAM lParam)
{
DWORD dwID;GetWindowThreadProcessId(hWnd, &dwID); if(dwID == (DWORD)lParam) { char Title\[MAX\_PATH\]; Title\[0\] = 0; GetWindowText(hWnd, Title, sizeof(Title)); if(IsWindowEnabled(hWnd) && Title\[0\]!= 0 && Proc\_Argument\[0\]!= 0) { if(strcmp(Proc\_Argument , "-wmc") == 0) SendMessage(hWnd, WM\_CLOSE, 0, 0 ); else if(strcmp(Proc\_Argument , "-wmq") == 0) PostMessage(hWnd, WM\_QUIT, 0, 0); else if(strcmp(Proc\_Argument, "-scl") == 0) PostMessage(hWnd, WM\_SYSCOMMAND,SC\_CLOSE,0); else MessageBox(NULL,"Invalid Arguments", "Error", MB\_OK); } } return TRUE;
}
So i need to know whether i'm doing right? Thanks All..
modified on Monday, September 7, 2009 4:39 AM
-
Hello all.. I'm making an application which terminate other processes in different way, i.e using TerminateProcess, WM_CLOSE, WM_QUIT, SC_CLOSE. Now i'm able to terminate process in all the way, But i need bit explanation in WM_CLOSE, WM_QUIT and SC_CLOSE.. How exactly it closes other process?? I believe there are two conditions which need to be fulfilled. 1> The target process has at least one window. 2> The target process doesn't handle the WM_CLOSE, WM_QUIT, SC_CLOSE message. So i'm doing this to enumerates all top level windows, In LPARAM i'm passing the pid of the target process..
EnumWindows((WNDENUMPROC)Enum_Terminate_Process, (LPARAM) aiPID[i]);
And in Enum_Terminate_Process, I'm doing something like this..
BOOL CALLBACK Enum_Terminate_Process(HWND hWnd, LPARAM lParam)
{
DWORD dwID;GetWindowThreadProcessId(hWnd, &dwID); if(dwID == (DWORD)lParam) { char Title\[MAX\_PATH\]; Title\[0\] = 0; GetWindowText(hWnd, Title, sizeof(Title)); if(IsWindowEnabled(hWnd) && Title\[0\]!= 0 && Proc\_Argument\[0\]!= 0) { if(strcmp(Proc\_Argument , "-wmc") == 0) SendMessage(hWnd, WM\_CLOSE, 0, 0 ); else if(strcmp(Proc\_Argument , "-wmq") == 0) PostMessage(hWnd, WM\_QUIT, 0, 0); else if(strcmp(Proc\_Argument, "-scl") == 0) PostMessage(hWnd, WM\_SYSCOMMAND,SC\_CLOSE,0); else MessageBox(NULL,"Invalid Arguments", "Error", MB\_OK); } } return TRUE;
}
So i need to know whether i'm doing right? Thanks All..
modified on Monday, September 7, 2009 4:39 AM
gothic_coder wrote:
So i need to know whether i'm doing right?
The above looks fine, so yes you are doing it right. However, it is up to the receiving process to decide how it handles these messages, so you need to check that those processes will terminate correctly on receipt of whichever message they are sent.
-
gothic_coder wrote:
So i need to know whether i'm doing right?
The above looks fine, so yes you are doing it right. However, it is up to the receiving process to decide how it handles these messages, so you need to check that those processes will terminate correctly on receipt of whichever message they are sent.
Alright.. Thanks for confirming :)
-
gothic_coder wrote:
So i need to know whether i'm doing right?
The above looks fine, so yes you are doing it right. However, it is up to the receiving process to decide how it handles these messages, so you need to check that those processes will terminate correctly on receipt of whichever message they are sent.
-
Check his post history. He does not have the capability to explain, only criticize.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons