简体   繁体   中英

Hiding command prompt while starting a process in C++

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.

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM