0

I have to start a process from my C++ code. I am using CreateProcess() function and I have set the following flags in the startupinfo struct. But still the command prompt shows up which I have to close manually to proceed. Please tell me how I can hide this command prompt during th e start up of the process.

si.cb = sizeof(STARTUPINFO);
    si.dwFlags = STARTF_USESHOWWINDOW;
    si.wShowWindow = SW_HIDE;

the create process call looks like this:

CreateProcess( NULL,   // No module name (use command line)
        exe,            // Command line
        NULL,           // Process handle not inheritable
        NULL,           // Thread handle not inheritable
        FALSE,          // Set handle inheritance to FALSE
        CREATE_NEW_CONSOLE,              // No creation flags
        NULL,           // Use parent's environment block
        NULL,           // Use parent's starting directory 
        &si,            // Pointer to STARTUPINFO structure
        &pi );

exe is a string containing the process name to start.

Please tell me how to hide this command prompt during start up of the process. I tried the method described here but it doesn't work. I have a Windows 7 system.

Thanks, Rakesh.

2
  • 1
    Are you the author of the other program? If so, is the entry point main() or WinMain() ? Commented Sep 11, 2012 at 10:28
  • No, I am not the author of the other program, so I don't know which one of them is used. Commented Sep 11, 2012 at 10:34

2 Answers 2

1

As MSalters says, the CREATE_NEW_CONSOLE is not what you want. But you probably also want to pass CREATE_NO_WINDOW to the CreateProcess function. See the MSDN documentation on what you can pass to CreateProcess as flags.

Sign up to request clarification or add additional context in comments.

2 Comments

I changed to CREATE_NO_WINDOW but still it doesn't solve my problem. Am I missing anything?
CREATE_NO_WINDOW is enough. Sounds like the other program is creating the console with AllocConsole.
1

You're passing CREATE_NEW_CONSOLE and you do NOT want a new console window. Seems like the answer is entirely obvious. Still, if the other process creates a console itself, then you cant prevent it. What happens if you start that process via Explorer?

1 Comment

The other process does not start any command prompt when started from explorer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.