ComputerMonitor.py 688 B

123456789101112131415161718192021222324252627282930313233
  1. import threading
  2. from ctypes import *
  3. import time
  4. import subprocess
  5. class ComputerMonitor:
  6. def __init__(self, callback):
  7. self.callback = callback
  8. self.started = False
  9. def monitor(self):
  10. self.monit_windows_lock()
  11. def monit_windows_lock(self):
  12. while True:
  13. process_name='LogonUI.exe'
  14. callall='TASKLIST'
  15. outputall=subprocess.check_output(callall)
  16. outputstringall=str(outputall)
  17. if process_name in outputstringall:
  18. print("Locked.")
  19. if self.callback:
  20. self.callback()
  21. else:
  22. pass
  23. time.sleep(1)
  24. def start(self):
  25. monitor_threading = threading.Thread(target=self.monitor, args=())
  26. monitor_threading.start()
  27. self.started = True