SHELLEXECUTEINFO

SHELLEXECUTEINFO 是Windows API ShellExecuteEx的参数,这个是一个结构体类型,里面可以添加参数,当IpVerb成员为 "runas"的时候可以提升启动进程的权限,如果不设置,会继承父进程的权限,ShellExecuteEx

 

std::string strOpEXEPath = _strOpEXEPath;

 

SHELLEXECUTEINFO sei = { 0 };

DWORD ExitCode = 0;

 

// Initialize for ShellExecuteEx

sei.cbSize = sizeof(SHELLEXECUTEINFO);

sei.fMask = SEE_MASK_NOCLOSEPROCESS;

sei.lpVerb = "runas";

sei.lpFile = strOpEXEPath.c_str();

sei.lpParameters = strConfigINIFile2.c_str();

sei.lpDirectory = NULL;

sei.nShow = SW_HIDE;

 

BOOL hr = ::ShellExecuteEx(&sei);

 

if ((LONG)sei.hInstApp > 32)

{

DWORD ResultWait = WaitForSingleObject(sei.hProcess, INFINITE);

if (ResultWait == WAIT_TIMEOUT)

{

TerminateProcess(sei.hProcess, 0);

}

 

GetExitCodeProcess(sei.hProcess, &ExitCode);

CloseHandle(sei.hProcess);

}

  

 

posted @ 2021-12-03 10:31  骄傲到自负  阅读(557)  评论(0编辑  收藏  举报