SHELLEXECUTEINFO ShExecInfo={0};
ShExecInfo. CbSize=sizeof (SHELLEXECUTEINFO);
ShExecInfo. FMask=SEE_MASK_NOCLOSEPROCESS;
ShExecInfo. HWND=NULL;
ShExecInfo. LpVerb=_T (" runas ");
ShExecInfo. LpFile=lpszAppPath;
ShExecInfo. LpParameters=lpParameters;
ShExecInfo. LpDirectory=lpszDirectory;
ShExecInfo. NShow=SW_HIDE;
ShExecInfo. HInstApp=NULL;
if (! ShellExecuteEx (& amp; ShExecInfo))
{
return 0;
}
//WaitForSingleObject (ShExecInfo hProcess, INFINITE).
If (WaitForSingleObject (ShExecInfo hProcess, dwMilliseconds)==WAIT_TIMEOUT)
{
The TerminateProcess (ShExecInfo. HProcess, 0);
return 0;
}
DWORD dwExitCode;
if (! GetExitCodeProcess (ShExecInfo hProcess, & amp; DwExitCode))
{
return 0;
}
In a button click event to other tools, will be stuck for a period of time, the problem, how should solve? Or, what better way to allow for MFC program waiting for the other tool after operation and automatically shut down, there will not be stuck for a period of time?
CodePudding user response:
The WaitForSingleObject here is obstructive operationThe simplest BeginWaitCursor EndWaitCursor contains long time operation
If there are other mission requirements, can consider the timer testing or use the background thread
CodePudding user response: