0

I need Python event that should log present time into a file when windows receive sleep request. Below is my main code,

import subprocess

# Here code required to log the time at which system going to sleep
command = 'Sleep.py'
# Some usefull stuff
if subprocess.call(command, shell=True):
    print 'Success'
else:
    print 'Fail'

Below is 'Sleep.py' code,

import os
os.system("Rundll32.exe Powrprof.dll,SetSuspendState Sleep")

Can any one please provide solution to this

Subbu
  • 3
  • 1
  • AFAIK, there is no simple way to do this. You will need to listen for the WM_POWERBROADCAST message. you can see some kind of examples here: https://stackoverflow.com/questions/1411186/python-windows-shutdown-events – Jacobr365 May 09 '18 at 16:04
  • Thanks a lot @Jacobr – Subbu May 10 '18 at 12:24
  • @jacobr, can you please make your comment as answer. – Subbu May 12 '18 at 12:07

1 Answers1

0

Moved to answer as requested by asker.

As far as I know, there is no simple way to do this. You will need to listen for the WM_POWERBROADCAST message. You can see an example of listening for the shutdown event here: shutdown example

It should be similar except you are listening for WM_POWERBROADCAST with PBT_APMSUSPEND.

You can read about WM_POWERBROADCAST Here

You can read about PBT_APMSUSPEND Here

Jacobr365
  • 846
  • 11
  • 24