我通过 ShellExecuteEx 启动 exe:
tstring sPath = _T("C:\\Test\\MyApp.exe");
tstring sArgs = _T("/S");
SHELLEXECUTEINFO lpExecInfo = {0,};
lpExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
lpExecInfo.lpFile = sPath.c_str();
lpExecInfo.fMask=SEE_MASK_NOASYNC ;
lpExecInfo.hwnd = NULL;
lpExecInfo.lpVerb = NULL;
lpExecInfo.lpParameters = sArgs.c_str();
lpExecInfo.lpDirectory = NULL;
lpExecInfo.nShow = SW_SHOWNORMAL;
if (!ShellExecuteEx(&lpExecInfo)) {
// handle the error
throw CException("Cannot launch an application");
}
int nRes = (int)lpExecInfo.hInstApp; // nRes = 42
DWORD dwErr = GetLastError(); // dwErr = 0
如何检测 UAC 是否取消了启动?在这种情况下,ShellExecuteEx 成功(hInstApp = 42,GetLastError 返回 0)。
谢谢