I'm using automation to test an application, but sometimes I want to start the application via a batch file. When I run "process.WaitForInputIdle(100)" I get an error:
"WaitForInputIdle failed. This could be because the process does not have a graphical interface."
How can I tell if the process has a graphical interface or not?
See Environment.UserInteractive. That will identify whether the process has an interface at all, e.g. services are not user interactive.
You could also look at Process.MainWindowHandle which will tell you whether there is a graphical interface.
A combination of these two checks should cover all the possibilities.
As well as a
MainWindowHandle
check, one can enumerate the process threads and check if any of them reference a visible window via P/Invokes. This seems to do a good job catching any windows that the first check misses.You can simply try and catch the exception:
I was think along the lines of this, Still ugly but trys to avoid exceptions.