[python-win32] rebooting windows from Python?

Alec Bennett whatyoulookin at yahoo.com
Fri Dec 5 11:48:00 CET 2008


And thus I say for the second time in 24 hours: Eureka!

For anyone else coming down this path, here's how to shutdown, reboot or logoff Windows, each with the option to force the action. In other words, you can force Windows to reboot even if its asking if you want to save a document. 

<code>

nLogOff=0 
nReboot=2 
nForceLogOff=4 
nForceReboot=6 
nPowerDown=8 
nForcePowerDown=12

import wmi
wmi.WMI(privileges=["Shutdown"]).Win32_OperatingSystem()[0].Win32Shutdown (Flags=nForceReboot)

</code>

As is probably pretty obvious, change the "Flags" parameter to whatever you want from the list of options above.

On the off chance anyone's curious what my questions have been about, its a sleep timer to shutdown winamp, itunes, vlc, etc., or shutdown windows after a period of time. So now I can be a total slacker and fall asleep to a DVD and not have the menu music playing all night long.

http://gizmoware.net/sleeper







      


More information about the python-win32 mailing list