OS Reboot, Shutdown, Hibernate, Sleep, Wakeup (Windows Python)

扶醉桌前 提交于 2019-12-01 17:08:35

I also went with the command line:

import os
os.system(r'%windir%\system32\rundll32.exe powrprof.dll,SetSuspendState Hibernate')
sherpya

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 usectypessince looks like pywin32 does not implement it.

Wakeup? I doubt you can execute code while sleeping. :)

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!