启动进程并监听其生命周期是否结束(绕过CreateProcessWithAdmin管理员身份)

源码如下(亲测有效):

SHELLEXECUTEINFO info;
ZeroMemory(&info, sizeof(info));
info.cbSize = sizeof(SHELLEXECUTEINFO);
info.fMask = SEE_MASK_NOCLOSEPROCESS;
info.hwnd = NULL;
info.lpVerb = L"open";
info.lpFile = L"C:\\Windows\\SysWOW64\\Macromed\\test.exe";
info.lpParameters = L"";
info.lpDirectory = NULL;
info.nShow = SW_SHOW;
info.hInstApp = NULL;
BOOL bRet = ShellExecuteEx(&info);
if (bRet)
{
    DWORD dwProcessId = ::GetProcessId(info.hProcess);
    WaitForSingleObject(info.hProcess, INFINITE);

}

你可能感兴趣的:(c++)