Solved

Exit Windows

Posted on 2000-05-07
9
875 Views
Last Modified: 2008-02-26
Hy!

How to exit Windows with Delphi?? I had a API function but I can't find it!

Can you help me?!

Thanks

Robert Wismet
0
Comment
Question by:rowisoft
  • 2
  • 2
  • 2
  • +3
9 Comments
 
LVL 1

Expert Comment

by:tomer_engel
ID: 2785583
from the Win32 API Documantaion
(for learning  purpses only-not comecial)

ExitWindowsEx          
 
 The  ExitWindowsEx  function either logs off, shuts down, or shuts down and restarts the system.  
 
 BOOL ExitWindowsEx(
 
      UINT   uFlags ,           // shutdown operation    
     DWORD   dwReserved             // reserved    
    );             
   
 
 Parameters
 
 uFlags
 
 Specifies 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 Remarks 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 Remarks 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 Remarks section.    Windows 95:  Security privileges are not supported or required.    
   
 
 dwReserved
 
 Reserved; this parameter is ignored.  
 
   
 
 Return Values
 
 If the function succeeds, the return value is nonzero.
  If the function fails, the return value is zero. To get extended error information, call  GetLastError .  
 
 Remarks
 
 The  ExitWindowsEx  function returns as soon as it has initiated the shutdown. The shutdown or logoff then proceeds asynchronously.  
  During a shutdown or log-off operation, applications that are shut down are allowed a specific amount of time to respond to the shutdown request. If the time expires,  Windows displays a dialog box that allows the user to forcibly shut down the application, to retry the shutdown, or to cancel the shutdown request. If the EWX_FORCE  value is specified, Windows always forces applications to close and does not display the dialog box.  
 
 The  ExitWindowsEx  function sends a separate notification message, CTRL_SHUTDOWN_EVENT or CTRL_LOGOFF_EVENT as the situation warrants, to console  processes. A console process routes these messages to its  HandlerRoutine  functions, which are added and removed by calls to the  SetConsoleCtrlHandler  function.  ExitWindowsEx  sends these notification messages asynchronously; thus, an application cannot assume that the console notification messages have been handled when  a call to  ExitWindowsEx  returns.  
 
 Windows NT:  To shut down or restart the system, the calling process must use the  AdjustTokenPrivileges  function to enable the SE_SHUTDOWN_NAME privilege. For  more information about security privileges, see  Privileges .  
  Windows 95:  Security privileges are not supported or required.
 
 See Also
 
 AdjustTokenPrivileges ,  ExitWindows ,  HandlerRoutine ,  SetConsoleCtrlHandler  
 
 
Have fun    Tomer
0
 

Expert Comment

by:sarc
ID: 2786076
Or use

"InitiateSystemShutDown" from the same family ;-)

(just as an addition)
0
 

Expert Comment

by:Grayl1
ID: 2786414
Hi!

Use ExitWindowsEx(EWX_SHUTDOWN, 0); to exit windows form Delphi.
U can also use ExitWindowsEx(EWX_FORCE + EWX_SHUTDOWN, 0); to force windows to exit without any questions if U want to save an unsaved file and things like that.
In stead of EWX_SHUTDOWN U can use EWX_REBOOT or EWX_LOGOFF to reboot or logoff...
0
 
LVL 1

Expert Comment

by:saulite
ID: 2787552
Use this command    

        ExitWindowsEx(uFlags,0);

uFlags: you can combine following values:
   
  $0   (EWX_LOGOFF)           - log off
  $1   (EWX_SHUTDOWN)     - shut down
  $2   (EWX_REBOOT)          - reboot computer
  $4   (EWX_FORCE)             - force to terminate processes
  $8   (EWX_POWEROFF)      - turn off power
  $10 (EWX_FORCEIFHUNG) - force if hunged
  $44  - undocumented         - restarts Windows (same as hold down Shift                                                 key while pressing Ok on restart)

0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 1

Accepted Solution

by:
tomer_engel earned 10 total points
ID: 2787839
u know saulit,,that's preety rude of you
i commnted the SAME answer    24 hours before YOU ,SO DO THE      RIGHT  THING!!!!!!!!!!!!!!!!
0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 2861629
funny - 3 identical answers.
looks like some guys are unable to read...
ok, maybe it's just because they're relatively new to X-X
(Grayl1: 00-03-30 / saulite: 00-05-03)

apart from that - saulite:
there's some rules here.

one of these rules:
read the history before adding a comment

another rule:
you only post an answer when the questioner has checked the comments and tells you your answer is good so you can go ahead and post an answer. not before that. clear?

;-)

robert: i'd suggest to reject the answer so tomer can lock it and then you give him the points he deserves, ok?

bye,


BlackDeath.
0
 
LVL 1

Author Comment

by:rowisoft
ID: 2862768
Comment accepted as answer
0
 
LVL 1

Expert Comment

by:saulite
ID: 2865445
Ok. I'm sorry. Well, i'll try to be more careful, in future.
0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 2867655
no prob, man.

sorry for being rude.

thassa rite way.

bye & have a nice day,

BlackDeath.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now