天天看點

c語言程式 管理者,ShellExecuteEX(擷取管理者權限) | C/C++程式員之家

ShellExecuteEx取得管理者權限,ShellExecuteEx取得管理者權限

[cpp]

void GainAdminPrivileges(UINT idd, BOOL bWait){

CString strCmd;

CString strApp;

strCmd.Format (_T("/adminoption %d"), idd);

CSVPToolBox svpTool;

strApp = svpTool.GetPlayerPath();

SHELLEXECUTEINFO execinfo;

memset(&execinfo, 0, sizeof(execinfo));

execinfo.lpFile = strApp;

execinfo.cbSize = sizeof(execinfo);

execinfo.lpVerb = _T("runas");

execinfo.fMask = SEE_MASK_NOCLOSEPROCESS;

execinfo.nShow = SW_SHOWDEFAULT;

execinfo.lpParameters = strCmd;

ShellExecuteEx(&execinfo);

if(bWait)

WaitForSingleObject(execinfo.hProcess, INFINITE);

}

[/cpp]