BOOL InitiateSystemShutdown(lpszMachineName, lpszMessage, dwTimeout, fForceAppsClosed, fReboot) | |||||
LPTSTR lpszMachineName; | /* name of machine to shut down | */ | |||
LPTSTR lpszMessage; | /* message to display in dialog box | */ | |||
DWORD dwTimeout; | /* time to display dialog box | */ | |||
BOOL fForceAppsClosed; | /* force apps with unsaved changes? | */ | |||
BOOL fReboot; | /* reboot after shutdown? | */ |
The InitiateSystemShutdown function initiates a shutdown and optional rebooot of the specified machine.
lpszMachineName
Points to the null-terminated string that specifies the network machine name of the machine to shut down. If lpszMachineName is NULL or points to an empty string, the function shuts down the local machine.
lpszMessage
Points to a null-terminated string that specifies a message to display in a dialog box which prompts an interactive user to log off. This parameter can be NULL if no message is required.
dwTimeout
Specifies the time (in seconds) that the dialog box should be displayed. While this dialog box is displayed, the shutdown can be stopped by the AbortSystemShutdown function.
If dwTimeout is zero, the machine shuts down without displaying the dialog box, and the shutdown cannot be stopped by AbortSystemShutdown.
fForceAppsClosed
If TRUE, applications with unsaved changes are forcibly closed. If FALSE, a dialog box is displayed prompting the user to close the applications.
fReboot
If TRUE, the machine will immediately reboot after shutting down. If FALSE, the system will flush all caches to disk, clear the screen, and display a message indicating that it's safe to power down.
The return value is TRUE if the function was successful, or FALSE if an error occurred. Use the GetLastError function to obtain extended error information. Common failures include invalid or inaccessible machine name or insufficient privilege.
If a timeout time is specified (dwTimeout is not zero), a dialog box on the specified machine prompts the user to log off, displaying the username of the caller and the message at lpszMessage. The dialog box beeps at the time it is created, and remains on top of other windows in the system. The dialog can be moved but not closed. A timer counts down the remaining time before a forced shutdown. If the user logs off, Windows NT shuts down immediately. Otherwise, the machine is shut down when the timer expires.
The calling process must have SeShutdownPrivilege to shut down the local machine. The caller must have SeRemoteShutdownPrivilege on the target machine to shut down a remote machine. By default, users will have privilege to shut down the machine which they are logged onto, while administrators will have privilege to shut down a remote machine.
AbortSystemShutdown