问题
I'm looking for an automatize way of doing Windows Power Management functions: - Reboot - Shutdown - Hibernate - Sleep - Wakeup
Is there a Python module to cover this functionality? Of course any other solutions are also appreciated...
回答1:
I also went with the command line:
import os
os.system(r'%windir%\system32\rundll32.exe powrprof.dll,SetSuspendState Hibernate')
回答2:
See win32api.ExitWindowsEx() ActiveState documentation.
for flags: http://msdn.microsoft.com/en-us/library/aa376868%28v=vs.85%29.aspx
for hybernate/sleep:
http://msdn.microsoft.com/en-us/library/aa373201%28v=vs.85%29.aspx
to use this one you need to usectypes
since looks like pywin32
does not implement it.
Wakeup? I doubt you can execute code while sleeping. :)
回答3:
Unfortunately, my reputation doesn't allow me to comment on an answer (yet). But I came here looking for an alternative because I was trying to avoid using the command line, so I just have to say this: I don't think calling SetSuspendState directly is the answer.
Take a look here for a reason: http://blogs.msdn.com/b/oldnewthing/archive/2004/01/15/58973.aspx (short version: bad things may happen. Long version: unexpected function signature corrupts the stack).
If you need another reason, it seems to simply... not work in Win7 (no matter what you pass as parameters, it always goes to hibernate - never to standby). At least that's what happened to me, and from what I read online I'm not the only one.
来源:https://stackoverflow.com/questions/2673707/os-reboot-shutdown-hibernate-sleep-wakeup-windows-python