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

后端 未结 3 1114
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-18 09:25

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 th

相关标签:
3条回答
  • 2021-01-18 09:42

    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. :)

    0 讨论(0)
  • 2021-01-18 09:42

    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.

    0 讨论(0)
  • 2021-01-18 09:56

    I also went with the command line:

    import os
    os.system(r'%windir%\system32\rundll32.exe powrprof.dll,SetSuspendState Hibernate')
    
    0 讨论(0)
提交回复
热议问题