MFC运行外部exe并得到返回值

unsigned long Result; 
CString strWorkPath = szWorkPath;
CString strRes;
strWorkPath += _T("\\netcfg\\");
SHELLEXECUTEINFO ShExeInfo = {0};
ShExeInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExeInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExeInfo.hwnd = NULL;
ShExeInfo.lpVerb = NULL;
ShExeInfo.lpFile = _T("netcfg.exe");
ShExeInfo.lpParameters = _T("-l netlwf.inf");
ShExeInfo.lpDirectory = strWorkPath;
ShExeInfo.nShow = SW_HIDE;
ShExeInfo.hInstApp = NULL;
ShellExecuteEx(&ShExeInfo);
WaitForSingleObject(ShExeInfo.hProcess, 1000 * 120);
GetExitCodeProcess(ShExeInfo.hProcess, &Result);  
if (0 != Result)
{
	CString strCmd = _T("-l \"");
	strCmd += strInfPath + _T("\"  -c s -i");
	ShExeInfo.lpFile = strNetExePath;
	ShExeInfo.lpParameters = strCmd;
	ShellExecuteEx(&ShExeInfo);
	WaitForSingleObject(ShExeInfo.hProcess, 1000 * 120);
}
Result为外部exe的返回值,使用ShellExecuteEx创建进程而没有使用CreateProcess,因为发现CreateProcess创建netcfg.exe总是失败

你可能感兴趣的:(MFC,C++)