Doubt

  • Thread starter Thread starter Baskar RajaSekharan
  • Start date Start date
B

Baskar RajaSekharan

Hi,

Please clarifiy my doubt.


In C# Without using Any API Calls, is there any way to get the ProcessID
by giving the Handle of the Form.


I go through System.Disagnositcs, It's not accepting the Handle to kill the
Process. It's accepting the Name only. or ProcessId. To Use the Methods
I want to know the Process Id. Please let me know how to dothat?

Regards,
R.Baskar
 
If I'm understanding you correctly you have a window handle, right? Use
GetWindowThreadProcessId through P/Invoke to get the ID, and then kill the
process.
 
Hi,

If you want to close an application by knowing its main window HWND (which
is actually returned by Form.Handle), you could do the following:

PostMessage(handle, WM_QUIT, 0, 0)

(assuming the PostMessage P/Invoke function and WM_QUIT constant are
declared elsewhere)

MSDN does not recommend sending this message and advises to use
PostQuitMessage instead, but the latter cannot be used for another thread or
process.

You can also use WM_CLOSE, this could be even better (I used WM_QUIT since
the application I wanted to close didn't have any windows).
 
Back
Top