0

我正在尝试编写一个应用程序来打开另一个并自行关闭,所以当外部应用程序打开时我不需要控制台

这是我迄今为止尝试过的:

system("cmd.exe /c application.exe"); //console shows, application opens, console wait

system("start \"\" application.exe"); //console shows, application opens, console close

//console does not show but neither the application (I can see it in task manager)
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb           = sizeof(si);
si.dwFlags      = STARTF_USESHOWWINDOW;
si.wShowWindow  = SW_HIDE;
ZeroMemory(&pi, sizeof(pi));
CreateProcess(0, "application.exe", 0, 0, FALSE, 0, 0, 0, &si, &pi);

//console does not show but neither the application (I can see it in task manager)
WinExec("application.exe", SW_HIDE);

这是我编译的方式:

g++ -o "launcher" "launcher.cpp" -mwindows
4

1 回答 1

1

这是一些可以帮助我实现目标的代码:

// Declare and initialize process blocks
PROCESS_INFORMATION processInformation;
STARTUPINFO startupInfo;

memset(&processInformation, 0, sizeof(processInformation));
memset(&startupInfo, 0, sizeof(startupInfo));
startupInfo.cb = sizeof(startupInfo);

// Call the executable program
TCHAR cmd[] =  myCommandText;

int result = ::CreateProcess(NULL, cmd, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS|CREATE_NO_WINDOW, NULL, NULL, &startupInfo, &processInformation);

在这种情况下,myCommandText是一个控制台命令

于 2014-07-22T18:08:10.617 回答