Getting the shape of the baby process

I am trying to get the basic form of the process that I started, but FromChildHandle and FromHandle always return null. however, MainWindowHandle is nonzero.

IntPtr p = process_wrapper.MainWindowHandle; Form form = (Form) Control.FromChildHandle(p); if (form != null) { form.Close(); } 
+7
c # forms
source share
1 answer

You can only get the form as a control if the corresponding form was generated by your application. You cannot get the form from another process, because your parent process does not know about the mapping Control mapping handle of the child process.

If you just want to β€œstop” the child process ( form.close() ?), You can simply stop the complete process. Either "Clear" or by force:

process.CloseMainWindow() vs process.kill()

+2
source share

All Articles