Click here to Skip to main content
15,669,039 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using wmi as a watcher for insertion of a usb drive. Is there a way to elegantly stop the watcher if the usb event never occurs and user wants to abort? Can this somehow be combined with a keyboard listener? Using Python 3.10 and Windows 10

def waitForUSB():
    import wmi

    raw_wql = "SELECT * FROM __InstanceCreationEvent WITHIN 2 WHERE TargetInstance ISA \'Win32_USBHub\'"
    c = wmi.WMI ()
    watcher = c.watch_for(raw_wql=raw_wql)
    while 1:
        usb = watcher ()

What I have tried:

Looking online without success
Updated 11-Feb-23 2:05am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900