bin*_*bob 57
如果它只是一个控制台应用程序,您也可以使用该CREATE_NO_WINDOW标志作为CreateProcess调用本身的一部分,例如
CreateProcess(NULL, lpszCommandLine, NULL, NULL, FALSE,
CREATE_NO_WINDOW, NULL, NULL, &si, &pi);
Run Code Online (Sandbox Code Playgroud)
另请参阅此页面以获取有关环境变量的信息.
ojb*_*ass 11
此处的以下链接描述了如何以静默方式创建窗口:
DWORD RunSilent(char* strFunct, char* strstrParams)
{
STARTUPINFO StartupInfo;
PROCESS_INFORMATION ProcessInfo;
char Args[4096];
char *pEnvCMD = NULL;
char *pDefaultCMD = "CMD.EXE";
ULONG rc;
memset(&StartupInfo, 0, sizeof(StartupInfo));
StartupInfo.cb = sizeof(STARTUPINFO);
StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow = SW_HIDE;
Args[0] = 0;
pEnvCMD = getenv("COMSPEC");
if(pEnvCMD){
strcpy(Args, pEnvCMD);
}
else{
strcpy(Args, pDefaultCMD);
}
// "/c" option - Do the command then terminate the command window
strcat(Args, " /c ");
//the application you would like to run from the command window
strcat(Args, strFunct);
strcat(Args, " ");
//the parameters passed to the application being run from the command window.
strcat(Args, strstrParams);
if (!CreateProcess( NULL, Args, NULL, NULL, FALSE,
CREATE_NEW_CONSOLE,
NULL,
NULL,
&StartupInfo,
&ProcessInfo))
{
return GetLastError();
}
WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
if(!GetExitCodeProcess(ProcessInfo.hProcess, &rc))
rc = 0;
CloseHandle(ProcessInfo.hThread);
CloseHandle(ProcessInfo.hProcess);
return rc;
}
Run Code Online (Sandbox Code Playgroud)
我认为getenv和setenv都可以吗?我不确定你在这方面要问的是什么.
| 归档时间: |
|
| 查看次数: |
51835 次 |
| 最近记录: |