STARTUPINFO *si = new STARTUPINFO[nProcNum];
PROCESS_INFORMATION *pi = new PROCESS_INFORMATION[nProcNum];
int nCurNum = 0;
string cPath;
EnterCriticalSection(&m_mapCs);
std::vector<ExeInfo>::iterator it = m_vctTask.begin(); // 启动任务
for(; it!=m_vctTask.end(); it++)
{
// 如果是子目录
if(strlen(it->TaskPath) > 0)
{
cPath = g_cRootDir + "\\" + it->TaskPath ;
SetCurrentDirectory(cPath.c_str());
sprintf(cCmdLine, "%s\\%s\\%s", g_cRootDir.c_str(),it->TaskPath,it->ExeName);
}
// 否则在当前目录下
else
{
sprintf(cCmdLine, "%s\\%s", g_cRootDir.c_str(),it->ExeName);
}
ZeroMemory( &si[nCurNum], sizeof(si[nCurNum]) );
si[nCurNum].cb = sizeof(si[nCurNum]);
ZeroMemory( &pi[nCurNum], sizeof(pi[nCurNum]) );
// 设置启动最小化
si[nCurNum].dwFlags = STARTF_USESHOWWINDOW;
si[nCurNum].wShowWindow = SW_MINIMIZE;
if(! ::CreateProcess (NULL, cCmdLine, NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &si[nCurNum],&pi[nCurNum]))
{
//error
sprintf(szLogBuf, "---%s(%d):[%s]启动[Process%d]失败,错误代码%d,请检查配置文件 \r\n", __FILE__, __LINE__, __FUNCTION__, nCurNum+1,GetLastError());
LOG4CPLUS_ERROR(m_oLog, szLogBuf);
}
SetCurrentDirectory(g_cRootDir.c_str());
nCurNum ++;
Sleep(100);
}//end for 启动任务
在新窗口启动控制台程序,并且最小化
最新推荐文章于 2024-04-23 01:27:28 发布