computer_monitor.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. '''
  4. @Contact : liuyuqi.gov@msn.cn
  5. @Time : 2022/10/05 06:14:26
  6. @License : Copyright © 2017-2022 liuyuqi. All Rights Reserved.
  7. @Desc :
  8. '''
  9. import threading
  10. from ctypes import *
  11. import time
  12. import subprocess
  13. class ComputerMonitor:
  14. '''
  15. '''
  16. def __init__(self, callback):
  17. self.callback = callback
  18. self.started = False
  19. def monit_windows_lock(self):
  20. while True:
  21. process_name='LogonUI.exe'
  22. callall='TASKLIST'
  23. outputall=subprocess.check_output(callall)
  24. outputstringall=str(outputall)
  25. if process_name in outputstringall:
  26. print("Locked.")
  27. if self.callback:
  28. self.callback()
  29. else:
  30. pass
  31. time.sleep(1)
  32. def start(self):
  33. monitor_threading = threading.Thread(target=self.monit_windows_lock, args=())
  34. monitor_threading.start()
  35. self.started = True