Advertisement
ILikeTurtles

USB Key/Lock v2

Oct 9th, 2015
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. # USB Key/Lock
  2. # Author: ILikeTurtles
  3. # Description: Poll USB devices every 1.5 seconds. If 'KEY' is missing, lock Windows.
  4. import win32com.client, time, ctypes
  5.  
  6. wmi = win32com.client.GetObject ("winmgmts:")
  7. current_state = 'unknown'
  8.  
  9. # Functions
  10. def check_key():
  11.     "Checks if 'key' is present"
  12.     KEY = "1504171129470875179607"
  13.     LOCK = False
  14.     for usb in wmi.InstancesOf ("Win32_USBHub"):
  15.         usbdid = usb.DeviceID
  16.         if usbdid.find(KEY) != -1:
  17.             LOCK = True
  18.     if LOCK:
  19.         return "unlocked";
  20.     else:
  21.         return "locked";
  22.  
  23. print("USB Lock by Aaron Henderson")
  24. print("System will lock without proper USB device.")
  25.  
  26. while True:
  27.     new_state = check_key()
  28.     if (new_state == 'locked') and (current_state == 'unlocked'):
  29.         ctypes.windll.user32.LockWorkStation()
  30.     else:
  31.         current_state = new_state
  32.     time.sleep(1.5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement