首页 > 代码库 > ShellExecuteEx 阻塞和异步调用进程的两种方法

ShellExecuteEx 阻塞和异步调用进程的两种方法

阻塞:

SHELLEXECUTEINFO ShExecInfo = { 0 };
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = (LPCWSTR)newAppPath.utf16(); // _telegramPath.toLocal8Bit().constData();
ShExecInfo.lpParameters = L"";
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOWNORMAL;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess, INFINITE);

异步:

ShellExecuteA(NULL, "open", _telegramPath.toLocal8Bit().data(),telegramStartParm.c_str(), NULL, SW_SHOWNORMAL); 

 

备注:SW_SHOWNORMAL表示管理员权限调用

ShellExecuteEx 阻塞和异步调用进程的两种方法