exitwindowsex(EWX_SHUTDOWN,0);//我是这样写的 错了吗

解决方案 »

  1.   

    ExitWindowsEx(Ewx_Force or Ewx_Reboot,0);//你试试这个语句
      

  2.   

    procedure TtvAPIThing.ShutDown;
    const
      SE_SHUTDOWN_NAME = 'SeShutdownPrivilege';   // Borland forgot this declaration
    var
      hToken       : THandle;
      tkp          : TTokenPrivileges;
      tkpo         : TTokenPrivileges;
      zero         : DWORD;
    begin
      if Pos( 'Windows NT', OSVersion ) = 1  then // we've got to do a whole buch of things
         begin
            zero := 0;
            if not OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken) then
               begin
                 MessageBox( 0, 'Exit Error', 'OpenProcessToken() Failed', MB_OK );
                 Exit;
               end; // if not OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken)
            if not OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken) then
               begin
                 MessageBox( 0, 'Exit Error', 'OpenProcessToken() Failed', MB_OK );
                 Exit;
               end; // if not OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken)
            // SE_SHUTDOWN_NAME
            if not LookupPrivilegeValue( nil, 'SeShutdownPrivilege' , tkp.Privileges[ 0 ].Luid ) then
               begin
                  MessageBox( 0, 'Exit Error', 'LookupPrivilegeValue() Failed', MB_OK );
                  Exit;
               end; // if not LookupPrivilegeValue( nil, 'SeShutdownPrivilege' , tkp.Privileges[0].Luid )
            tkp.PrivilegeCount := 1;
            tkp.Privileges[ 0 ].Attributes := SE_PRIVILEGE_ENABLED;        AdjustTokenPrivileges( hToken, False, tkp, SizeOf( TTokenPrivileges ), tkpo, zero );
            if Boolean( GetLastError() ) then
               begin
                  MessageBox( 0, 'Exit Error', 'AdjustTokenPrivileges() Failed', MB_OK );
                  Exit;
               end // if Boolean( GetLastError() )
            else
               ExitWindowsEx( EWX_FORCE or EWX_SHUTDOWN, 0 );
          end // if OSVersion = 'Windows NT'
       else
          begin // just shut the machine down
            ExitWindowsEx( EWX_FORCE or EWX_SHUTDOWN, 0 );
          end; // else
    end;
      

  3.   

    var
      hProcess, hToken, lBufferNeeded: Cardinal;
      tmpLuid: TLargeInteger;
      tkp, tkp1: TOKEN_PRIVILEGES;
    begin
      hProcess := GetCurrentProcess;
      OpenProcessToken(hProcess, (TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY), hToken);
      LookupPrivilegeValue('', 'SeShutdownPrivilege', tmpLuid);
      tkp.PrivilegeCount := 1;
      tkp.Privileges[0].Luid := tmpLuid;
      tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
      AdjustTokenPrivileges(hToken, False, tkp, sizeof(tkp1), tkp1, lBufferNeeded);  ExitWindowsEx(EWX_REBOOT + EWX_FORCE, 0);  // 重启
      // ExitWindowsEx(EWX_POWEROFF + EWX_FORCE, 0);  // 关机
    end;
      

  4.   

    来晚了,唉......ExitWindowsEx(Ewx_Force or Ewx_Reboot,0);在Win2K下是不行的