SHELLEXECUTEINFO「建议收藏」

2022-09-06 15:53:35 浏览数 (1)

大家好,又见面了,我是你们的朋友全栈君。

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

代码语言:javascript复制
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);

}

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/155025.html原文链接:https://javaforall.cn

0 人点赞