Take the 2-minute tour ×

(I've searched SO answers and found no clear solution to this problem.)

I'm working on a MFC GUI program. This program runs various child programs including console program and shell command script(.cmd).

Initially it displayed one GUI window and one console window (created with AllocConsole) because there are many console output from the child processes. But many users complained about the console window so we decided to hide the console window.

Firstly tried like below:

if (AllocConsole())
    ::ShowWindow(::GetConsoleWindow(), SW_HIDE);

Okay, no console window but there are visible flicker at the console creation time. I've tried several CreateProcess options for child process creation to prevent showing of console window altogether but failed at short and I think it is practically impossible.

It is not a big deal. We can ignore temporary window flicker at the startup.

But is it really impossible to hide child console window completely?

share|improve this question
The flicker is expected; you're creating a console window and then hiding it. The question is, why do you create a console window at all, if you don't want the user to see it? What's wrong with ShellExecute or CreateProcess? –  Cody Gray Jan 20 '11 at 4:58
@Code Gray This program CreateProcess various console programs. Without AllocConsole, separated and uncontrollable console window will be created, destroyed all the time. –  9dan Jan 20 '11 at 5:07
I have no idea what that means. You're running several different console programs, and if you use CreateProcess each time will create a new console window instead of reusing the old one? Yeah...so? What's wrong with that? –  Cody Gray Jan 20 '11 at 5:09
@Code Gray You'd better reread the title. I want to execute child console programs without showing the console window. –  9dan Jan 20 '11 at 5:12
The problem is, I don't know what "child console programs" are. I read the title carefully, and just now again. You are only asking how to make a child console window invisible. I'm questioning why you need the window at all, if the user doesn't need to be able to interact with the program running in that console window (your question indicates that you originally thought this to be the case, but have since changed your design). It's still not at all clear why these console applications you're running all need to be started from the same console window. –  Cody Gray Jan 20 '11 at 5:14
show 4 more comments

1 Answer

up vote 8 down vote accepted

Setup the STARTUPINFO like this for the CreateProcess call:

    STARTUPINFO si = { 0 };
    si.cb = sizeof(si);
    si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
    si.hStdOutput =  GetStdHandle(STD_OUTPUT_HANDLE);
    si.hStdError = GetStdHandle(STD_ERROR_HANDLE);
    si.wShowWindow = SW_HIDE;
share|improve this answer
Thank you! It works perfectly when use CreateProcess with CREATE_NO_WINDOW option. –  9dan Jan 20 '11 at 7:01
@9dan: Amazing! You solved your problem with CreateProcess after all. And I say that not just to be sassy, but because I honestly still don't understand the objection you were raising to using it when I asked you in the comments. –  Cody Gray Jan 20 '11 at 11:45
@Cody Gray: the problem is that CreateProcess by itself is insufficient, not that it's wrong. The I/O redirection and the CREATE_NO_WINDOW flag were also needed. –  MSalters Jan 20 '11 at 13:13
In C# use ProcessStartInfo and set WindowStyle = ProcessWindowStyle.Hidden. Pretty much the same just .NET Frameworked. –  Eve Aug 12 '13 at 8:35
add comment

Your Answer


