function TForm1.EnablePrivilege( ): Bool;
var
  hToken : THANDLE;
  fOk : Bool;
  fTest : Bool;
  tp, tpNew : TOKEN_PRIVILEGES;
  ReturnLength : Cardinal;
begin
  fOk := FALSE;
  if OpenProcessToken(GetCurrentProcess,(TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY),hToken)   then
      begin
      tp.PrivilegeCount := 1;
      if not (LookupPrivilegeValue('','SeRemoteShutdownPrivilege',tp.Privileges[0].Luid)) then
      ShowMessage('Can not lookup privilege value!!');
      tp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
      if not (AdjustTokenPrivileges(hToken,FALSE,tp,sizeof(tp),tpNew,ReturnLength)) then
      ShowMessage('Can not adjust privilege value!!');
      if GetLastError = ERROR_SUCCESS then
      fOk := TRUE
      else
      fOK := FALSE;
      CloseHandle(hToken);
    end;
  Result := fOk;
end;单独使用时还能够实现,但加在程序段中就出现:
[Error] Unit1.pas(1108): Ambiguous overloaded call to 'AdjustTokenPrivileges'错在哪里?如何修改呢?望高手指点!

解决方案 »

  1.   

    你是不是有多个 AdjustTokenPrivileges函数呢?
      

  2.   

    上述程序没任何问题,可能的原因是你在程序中定义了两个以上的AdjustTokenPrivileges函数
      

  3.   

    delphi8里面是不是去掉了AdjustTokenPrivileges等权限设置函数
      

  4.   

    把AdjustTokenPrivileges改成Windows.AdjustTokenPrivileges试试?
      

  5.   

    可以用getlasterr看一下最后系统报错的原因
      

  6.   

    SeRemoteShutdownPrivilege如果系统没有这个的话就会出错。