Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # USB Key/Lock
- # Author: ILikeTurtles
- # Description: Poll USB devices every 1.5 seconds. If 'KEY' is missing, lock Windows.
- import win32com.client, time, ctypes
- wmi = win32com.client.GetObject ("winmgmts:")
- current_state = 'unknown'
- # Functions
- def check_key():
- "Checks if 'key' is present"
- KEY = "1504171129470875179607"
- LOCK = False
- for usb in wmi.InstancesOf ("Win32_USBHub"):
- usbdid = usb.DeviceID
- if usbdid.find(KEY) != -1:
- LOCK = True
- if LOCK:
- return "unlocked";
- else:
- return "locked";
- print("USB Lock by Aaron Henderson")
- print("System will lock without proper USB device.")
- while True:
- new_state = check_key()
- if (new_state == 'locked') and (current_state == 'unlocked'):
- ctypes.windll.user32.LockWorkStation()
- else:
- current_state = new_state
- time.sleep(1.5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement