// hProcess [in] : 要提升的进程,目标进程
// lpPrivilegeName [in] : 要提升到的特权,目标特权
// 返回值 : TRUE : 成功; FALSE : 失败
BOOL UpdateProcessPrivilege( HANDLE hProcess, LPCTSTR lpPrivilegeName = SE_DEBUG_NAME )
{
HANDLE hToken;
if ( ::OpenProcessToken( hProcess, TOKEN_ALL_ACCESS, &hToken ) )
{
LUID destLuid;
if ( ::LookupPrivilegeValue( NULL, lpPrivilegeName, &destLuid ) )
{
TOKEN_PRIVILEGES TokenPrivileges;
TokenPrivileges.PrivilegeCount = 1;
TokenPrivileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
TokenPrivileges.Privileges[0].Luid = destLuid;
int iResult;
if ( iResult = ::AdjustTokenPrivileges( hToken, FALSE, &TokenPrivileges, 0, NULL, NULL ) )
{
return TRUE;
}
}
}
return FALSE;
}