Monday, October 27, 2008

How to find whether the parent process is GUI or Console

This is not 100% fool proof. How ever in normal cases, this works great. This technique can be used to find out, whether the child application was launched from a GUI application or from a Console application.

if( AttachConsole( ATTACH_PARENT_PROCESS ))
AfxMessageBox( _T("Parent process is a console application"));
AfxMessageBox( _T("Parent process is not a console application"));


  1. Hi Naveen,

    Another method would be iterating all of the parent process threads and calling the IsGUIThread Function to check if the Win32 subsystem (Win32k.sys) has promoted the thread. If any of the threads return TRUE then the parent process has a non-console window.

    Best Wishes,
    -David Delaune (Randor)

  2. Hi David,

    But that function needs to be called from the thread context, isnt it?