Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I tell if a process has a graphical interface?

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?

like image 244
Lunivore Avatar asked Sep 24 '10 09:09

Lunivore


People also ask

How should one use a graphical user interface?

There are some standards as to how one should use a Graphical User Interface. The Visibility and abstraction must be uniform, at least with GUI developed from a single company. Each and every GUI has its own features and functions, but the graphic elements and terminology of the system and its architecture must be well maintained.

What is a GUI interface?

GUI means Graphical User Interface. It is the common user Interface that includes Graphical representation like buttons and icons, and communication can be performed by interacting with these icons rather than the usual text-based or command-based communication.

What happens when an interface isn’t designed for its users?

If an interface isn’t built with its users in mind, no one will be able to find the information they need when they need it, nor will they remember where anything is. It’s like being caught in a rainstorm and not being able to open your umbrella.

What are icons in a graphical user interface?

Files, programs, web pages etc. can be represented using a small picture in a graphical user interface. This picture is known as an icon. Using an icon is a fast way to open documents, run programs etc. because clicking on them yields instant access.


2 Answers

You can simply try and catch the exception:

Process process = ...
try
{
    process.WaitForInputIdle(100);
}
catch (InvalidOperationException ex)
{
    // no graphical interface
}
like image 160
Dirk Vollmar Avatar answered Oct 05 '22 12:10

Dirk Vollmar


I was think along the lines of this, Still ugly but trys to avoid exceptions.

Process process = ...

bool hasUI = false;

if (!process.HasExited)
{
    try
    {
        hasUI = process.MainWindowHandle != IntPtr.Zero;
    }
    catch (InvalidOperationException)
    {
        if (!process.HasExited)
            throw;
    }
}

if (!process.HasExited && hasUI)
{

    try
    {
        process.WaitForInputIdle(100);
    }
    catch (InvalidOperationException)
    {
        if (!process.HasExited)
            throw;
    }
}
like image 44
Bear Monkey Avatar answered Oct 05 '22 10:10

Bear Monkey