CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 1999
    Location
    Darmstadt, FRG
    Posts
    87

    How to distinguish between process types

    Is anyone aware of a function which allows to detect whether a process-id or a process-handle refers to a console- or a GUI-process?

    Thanks for any comments in advance.
    Thomas

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: How to distinguish between process types

    Could GetGuiResources help you?
    Victor Nijegorodov

  3. #3
    Join Date
    Jul 2002
    Posts
    2,543

    Re: How to distinguish between process types

    Bad news that it is impossible to define exactly what is Console and GUI appllication. GUI application may have Console window. Console application can show modal dialog. Application may be non-GUI and non-Console, for example, service or Windows application which doesn't show any window. Program may work with DirectX full-screen mode, in this case it doesn't have any window.
    Regarding GetGuiResources - program can create GDI objects without GUI, for example, memory DC.
    Assuming that GUI application is one that has at least one window:
    Call EnumWindows,
    For every window handle, call GetWindowThreadProcessId to detect whether it belongs to the process. If at least one window belongs to the process - this is possibly GUI application.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: How to distinguish between process types

    Thank you Alex for useful information!
    Victor Nijegorodov

  5. #5
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: How to distinguish between process types

    Quote Originally Posted by Alex F View Post
    Assuming that GUI application is one that has at least one window:
    Call EnumWindows,
    For every window handle, call GetWindowThreadProcessId to detect whether it belongs to the process. If at least one window belongs to the process - this is possibly GUI application.
    Will work for many, but not all.
    As you said yourself, a Console application can have a messagebox, but it can also have any of the common dialogs, and an application can even start life as a console application, then make a full fledged GUI anyway.

    There's no easy solution here, and in fact a proper answer is really dependant on what you want to know.

    If you want to know how the application was built, you can use the processID to open a process handle, use that to get the process full filename, open this filename and read the PE header to check for the IMAGE_SUBSYSTEM_WINDOWS_GUI or IMAGE_SUBSYSTEM_WINDOWS_CUI flags in the optional header.

    But you can make an exe having the GUI flag that never ever makes a window, and you can have a CUI one that does makes windows and displays a GUI. Without being more specific as to what you're after, there is no single right answer.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured