Exit from Windows  

Send By: Q3 Team
Web : www.q3.nu
Email: dlib@q3.nu
Date: 03/05/01

Tip accessed 563 times

 


There are various manners to make it:


      ExitWindowsEx(EWX_SHUTDOWN,0);



Exit from Windows in a secure manner. Empty buffers and stop all applications.





      ExitWindowsEx(EWX_FORCE,0);



Force to process to finish. Instead of show the dialog (Application not responding), force to finish.





      ExitWindowsEx(EWX_LOGOFF,0);


Finish all applications executing in the equal security context that the caller process, and make a user log-off





      ExitWindowsEx(EWX_POWEROFF,0);


Finish all the applications and turn-off the computer





      ExitWindowsEx(EWX_REBOOT,0);



Finish all the applications and reboot the computer

WARNING: Test-it out from Delphi IDE




For Windows NT


In NT the things are different. We must be have acess for ShutDown the system. Here you have a function for make this. Is for a newsgroup, in a post of Daniel (daniel_dat@yahoo.es)


 function ShutDownWindows(Flag: word): Boolean;
 var
   TokenPriv: TTokenPrivileges;
   H: DWord;
   HToken: THandle;
 begin
   if Win32Platform = VER_PLATFORM_WIN32_NT then
     begin
       OpenProcessToken(GetCurrentProcess,
           TOKEN_ADJUST_PRIVILEGES,HToken);
       LookUpPrivilegeValue(NIL, 'SeShutdownPrivilege',
           TokenPriv.Privileges[0].Luid);
       TokenPriv.PrivilegeCount := 1;
       TokenPriv.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
       H := 0;
       AdjustTokenPrivileges(HToken, FALSE,
          TokenPriv, 0, PTokenPrivileges(NIL)^, H);
       CloseHandle(HToken);
     end;
   Result := ExitWindowsEx(Flag, 0);
 end;





Updated at 03/05/2001 (NT)