How to Shut Down the System

There are two ways for an application to shut down local or remote computers:

Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege to shut down the system.

To shut down the system, use the ExitWindowsEx function. The system sends the WM_QUERYENDSESSION message to each window, unless you called ExitWindowsEx with the EXW_FORCE flag. The applications perform any cleanup while processing WM_QUERYENDSESSION, and return TRUE to indicate that they can be terminated. If you use EXW_FORCE, applications may lose data. For more information, see Shutting Down.

Windows NT: The InitiateSystemShutdown function starts a timer and displays a dialog box that prompts the user to log off. While the dialog box is displayed, the AbortSystemShutdown function can stop the timer and prevent the computer from shutting down. However, if the timer expires, the computer is shut down. InitiateSystemShutdown can also restart the computer following a shutdown operation. For more information, see Displaying the Shutdown Dialog Box.