[python-win32] rebooting windows from Python?
Alec Bennett
whatyoulookin at yahoo.com
Fri Dec 5 10:35:48 CET 2008
> <code>
> import wmi
>
> wmi.WMI(privileges=["Shutdown"]).Win32_OperatingSystem()[0].Shutdown ()
>
> </code>
Stylin, works. The only thing it doesn't do that I personally need it to do is the "force shutdown". In other words "shutdown.exe -f". I found this page with some hints but couldn't get it to work:
http://www.freevbcode.com/ShowCode.asp?ID=7693
I tried:
nForcePowerDown=12
wmi.WMI(privileges=["Shutdown"]).Win32_OperatingSystem()[0].Shutdown (nForcePowerDown)
But no joy.
It looks like that code sample is referring to a function called Win32Shutdown(), which appears to be part of the WMI, but I couldn't get it to work. Here's the docs:
http://msdn.microsoft.com/en-us/library/aa394058(VS.85).aspx
I tried:
nForcePowerDown=12
wmi.WMI(privileges=["Shutdown"]).Win32_OperatingSystem()[0].Win32Shutdown(nForcePowerDown)
Interestingly that errors out with "_call__() takes exactly 1 argument (2 given)", meaning I think that the Win32Shutdown function doesn't take a parameter, even though the docs say it does.
More information about the python-win32
mailing list