Last Modification: August 12, 2000

How can I shutdown the system programmatically? 

The appropriately named ExitWindows() and ExitWindowsEx() functions do the trick. On Win9x, using them is pretty straightforward. On NT, however, the calling process must enable the SE_SHUTDOWN_NAME privilege explicitly before calling either of these functions. How to do this? by using AdjustTokenPrivileges(). You'll find examples on both issues below.

Also, on NT you'll find a very handy function called InitiateSystemShutdown(). It can basically do the same as ExitWindows(), except it allows you to shutdown remote systems. Remember that to do this, you need to have the SE_REMOTE_SHUTDOWN privilege granted on the remote computer, though.

References and samples: