I cannot seem to find a way to determine whether a Process
has a user interface e.g. a window, which is visible to the user?
Process
instance. EnumWindows
. GetWindowThreadProcessId
and see if it matches the target PID.IsWindowVisible
and/or IsIconic
to test if that window is visible to the user.The MSDN article about System.Diagnostics.Process.MainWindowHandle
states the following
If you have just started a process and want to use its main window handle, consider using the WaitForInputIdle method to allow the process to finish starting, ensuring that the main window handle has been created. Otherwise, an exception will be thrown.
What they are implying is that the Window
might take several seconds to render after you've made the call for the MainWindowHandle
, returning IntPtr.Zero
even though you can clearly see a Window
is shown.
See https://msdn.microsoft.com/en-us/library/system.diagnostics.process.mainwindowhandle(v=vs.110).aspx for reference