1.WinExec("cmd.exe",SW_SHOW);可以隐藏程序界面,一般在后台隐藏执行命令行或脚本时使用
2.system("cmd");直接执行命令,不可以隐藏界面
3.CreateProcess,一般执行带界面的进程,可以隐藏界面,隐藏方法要同时设置dwFlags和wShowWindow才可以生效,例如:
STARTUPINFO si;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
si.dwFlags=STARTF_USESHOWWINDOW;
si.wShowWindow=SW_HIDE;
ZeroMemory( &pi, sizeof(pi) );
//watchdog
if( !CreateProcess( NULL, // No module name (use command line).
TEXT("test.exe"), // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
0, // No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi) // Pointer to PROCESS_INFORMATION structure.
)
{
MessageBox("启动失败!");
exit(-1);
}