i am trying to get the main form of a process that i started, but the FromChildHandle and FromHandle always return null. the MainWindowHandle however is nonzero.
IntPtr p = process_wrapper.MainWindowHandle;
Form form = (Form) Control.FromChildHandle(p);
if (form != null)
{
form.Close();
}
You can only retrieve a form as a control, if the form in question has been generated by your application. You cannot retrieve a form from another process, as your parent process is not aware of the handle <->Control mapping of the child process.
If you just want to "stop" the child process (form.close()
?) You can simple stop the complete process. Either "Clean", or by force:
process.CloseMainWindow()
vs process.kill()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With