What is the difference between DETACH_PROCESS and CREATE_NO_WINDOW process creation flags for createProcess function

Viewed 6545

I have been trying to understand the difference between these two process creation flags. The msdn documentation is not clear about the distinction.

  • Does CREATE_NO_WINDOW causes the process to have a console (standard input/output streams initialized) without displaying a window while DETACH_PROCESS has no console at all?
  • What are the implications are for a child-of-a-child process?
  • What would be the behavior matrix that describes what happens at each combination of (parent has console, parent doesn't have console) X (child executable requires console (main), child executable does not require console (WinMain)).?
2 Answers

I have not tested what Hans Passant said about AttachConsole(ATTACH_PARENT_PROCESS). However, I have found another difference based on testing.

Let's define a process tree to better explain what I mean:

A
|
+-- B
    |
    +-- C

With DETACH_PROCESS, only the started process (B) has no console — by default. If the started process starts console child processes (C), then each of those child process will be started in a new console. Furthermore, the started process B (or its children C) can still create a console by calling AllocConsole.

CREATE_NO_WINDOW is a "nuclear option" that's stronger than DETACH_PROCESS. Even the started process' children (C) don't get a console, not even if they call AllocConsole. Furthermore, Ctrl-C'ing the topmost process (A) won't terminate B and C, so it seems that CREATE_NO_WINDOW also includes an effect similar to starting a new process group.

Related