[英]Hiding command prompt while starting a process in C++
I have to start a process from my C++ code. 我必须从我的C ++代码开始一个过程。 I am using CreateProcess() function and I have set the following flags in the startupinfo struct. 我正在使用CreateProcess()函数,我在startupinfo结构中设置了以下标志。 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: create process调用如下所示:
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. exe是一个包含要启动的进程名称的字符串。
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. 我有一个Windows 7系统。
Thanks, Rakesh. 谢谢,拉克什。
You're passing CREATE_NEW_CONSOLE
and you do NOT want a new console window. 您正在传递CREATE_NEW_CONSOLE
而您不需要新的控制台窗口。 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? 如果您通过Explorer启动该过程会发生什么?
As MSalters says, the CREATE_NEW_CONSOLE
is not what you want. 正如MSalters所说, CREATE_NEW_CONSOLE
不是你想要的。 But you probably also want to pass CREATE_NO_WINDOW
to the CreateProcess
function. 但是您可能还想将CREATE_NO_WINDOW
传递给CreateProcess
函数。 See the MSDN documentation on what you can pass to CreateProcess
as flags. 有关可以作为标志传递给CreateProcess
,请参阅MSDN文档 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.