The ExitWindowsEx function either logs off, shuts down, or shuts down and restarts the system. BOOL ExitWindowsEx(    UINT uFlags, // shutdown operation
    DWORD dwReserved  // reserved
   );
 ParametersuFlagsSpecifies the type of shutdown. This parameter must be some combination of the following values: Value Meaning
EWX_FORCE Forces processes to terminate. When this flag is set, Windows does not send the messages WM_QUERYENDSESSION and WM_ENDSESSION to the applications currently running in the system. This can cause the applications to lose data. Therefore, you should only use this flag in an emergency.
EWX_LOGOFF Shuts down all processes running in the security context of the process that called the ExitWindowsEx function. Then it logs the user off.
EWX_POWEROFF Shuts down the system and turns off the power. The system must support the power-off feature.Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Res section. Windows 95: Security privileges are not supported or required.
EWX_REBOOT Shuts down the system and then restarts the system. Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Res section. Windows 95: Security privileges are not supported or required.
EWX_SHUTDOWN Shuts down the system to a point at which it is safe to turn off the power. All file buffers have been flushed to disk, and all running processes have stopped. Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Res section. Windows 95: Security privileges are not supported or required.
 dwReservedReserved; this parameter is ignored.  Return ValuesIf the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.

解决方案 »

  1.   

    在win2k或NT下可用以下代码实现if OpenProcessToken(GetCurrentProcess ,TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY ,hToken) then
    begin
        LookupPrivilegeValue(Nil ,'SeShutdownPrivilege' ,tkp.Privileges[0].Luid) ;
        tkp.PrivilegeCount := 1;
        tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
        AdjustTokenPrivileges(hToken ,False ,tkp ,sizeof(tkp) ,otkp ,dwLen) ;
        if (GetLastError() <> ERROR_SUCCESS) then
        begin
            ShowMessage('AdjustTokenPrivileges enable failed.') ;
        end else
        begin
            ExitWindowsEx(EWX_REBOOT ,0) ;
        end ;
    end
      

  2.   

    实在对不起大家,我不是要restart widnows也不是要logoff windows
    我就是要重新启动我自己的程序,退出我自己的程序的登录。
      

  3.   

    刚刚试了一下,可以用:
    procedure TForm1.Button1Click(Sender: TObject);
    begin
    Close;
    WinExec(PChar('D:\Project1.exe'), 0);
    end;