Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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)).?
like image 867
Manny Avatar asked Jun 16 '11 11:06

Manny


People also ask

What happens when a win32 application calls CreateProcess?

If CreateProcess succeeds, it returns a PROCESS_INFORMATION structure containing handles and identifiers for the new process and its primary thread. The thread and process handles are created with full access rights, although access can be restricted if you specify security descriptors.

How does Windows create a new process?

The fundamental Windows process management function is CreateProcess, which creates a process with a single thread. Specify the name of an executable program file as part of the CreateProcess call. It is common to speak of parent and child processes, but Windows does not actually maintain these relationships.


1 Answers

The difference is in what the started process can do. In both cases it won't have a console. But with the CREATE_NO_WINDOW option it can call AttachConsole(ATTACH_PARENT_PROCESS) and get access to the parent's console window (if available). That explicitly will not work when you specify DETACH_PROCESS. The only option then is for the started process to use AllocConsole() to create its own console.

Or in other words, you can be sure that the started process will never be able to chatter into your own console by using DETACH_PROCESS.

like image 176
Hans Passant Avatar answered Oct 04 '22 03:10

Hans Passant