Occasionally, it’s necessary to force a Windows NT computer to reboot programmatically. You may need to perform a scheduled reboot of the current machine or force a reboot of a remote PC programmatically.
appears perfect for the job.
The name of the machine to shutdown or
the current machine.
A message to be displayed to the user in a dialog while the
timeout period expires.
A timeout in seconds, during which time a dialog is displayed warning the user of the pending shutdown. After the timeout expires, the shutdown process begins. If this is zero, the shutdown commences immediately.
Specifies whether applications with unsaved changes are to be
forcibly closed. If this parameter is
applications are closed. If this parameter is
false, a dialog box is displayed prompting the
user to close the applications. Note that this implies the user could
cancel the shutdown process by selecting Cancel in the dialog his
application displays for unsaved data.
Specifies whether the machine is rebooted after the shutdown process.
Let’s try this function. Start by rebooting the current machine with a 30-second timeout (without forcing applications shut) and finally restart after shutdown:
>>> import win32api >>> message = "This machine is being rebooted because it has been naughty" >>> win32api.InitiateSystemShutdown(None, ...