你的系统是NT(2K、XP)的吧,在这样的系统下是要取得权限的。

解决方案 »

  1.   

    没错,我一直用win2K,那我该如何获得系统权限呢?
      

  2.   

    winnt中获得SE_SHUTDOWN_NAME特权procedure TForm1.Button1Click(Sender: TObject);
    var
      hToken,ReturnLength: Cardinal;
      MyTokenPrivileges: TOKEN_PRIVILEGES;
    begin
      ReturnLength := 0;  Win32Check(OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,hToken));
      Win32Check(LookupPrivilegeValue(nil,'SeShutdownPrivilege',MyTokenPrivileges.Privileges[0].Luid));
      MyTokenPrivileges.PrivilegeCount := 1;  // one privilege to set
      MyTokenPrivileges.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
      Win32Check(AdjustTokenPrivileges(hToken,false,MyTokenPrivileges,0,nil,ReturnLength));
      Win32Check(CloseHandle(hToken));
      Win32Check(ExitWindowsEx(EWX_POWEROFF + EWX_FORCEIFHUNG, 0));
    end;
      

  3.   

    procedure Reboot_Computer();
    var
      hToken:THandle;
      tkp : TOKEN_PRIVILEGES;
      ReturnLength : DWord;
    begin
      if (not OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES or TOKEN_ALL_ACCESS or  TOKEN_QUERY, hToken))then
        begin
          application.Terminate;
        end;
      LookupPrivilegeValue(nil,'SeShutdownPrivilege',tkp.Privileges[0].Luid);
      tkp.PrivilegeCount := 1;
      tkp.Privileges[0].Attributes :=SE_PRIVILEGE_ENABLED;
      ReturnLength :=0;
      AdjustTokenPrivileges(hToken, FALSE, tkp, 0,nil,ReturnLength);
      if (GetLastError() <> ERROR_SUCCESS) then
        begin
          application.Terminate;
        end;
      if (not ExitWindowsEx(1, 0)) then
        begin
          application.Terminate;
        end;
    end;
    hehe,试试中吧
      

  4.   

    试试修改
    if (not ExitWindowsEx(1, 0)) then
        begin
          application.Terminate;
        end;
    中的1,来运行不同的关机选项