commit b261b5037919e759189b04484cde50548e9760b0 Author: William Lindholm <william_lindholm@outlook.com> Date: Fri, 29 Dec 2023 20:50:34 +0100 Initial commit. Diffstat:
| A | .idea/.gitignore | | | 8 | ++++++++ |
| A | main.py | | | 30 | ++++++++++++++++++++++++++++++ |
| A | requirements.txt | | | 0 |
3 files changed, 38 insertions(+), 0 deletions(-)
diff --git a/.idea/.gitignore b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +/vcs.xml +/USBDetective.iml +/inspectionProfiles/profiles_settings.xml +/modules.xml +/misc.xml diff --git a/main.py b/main.py @@ -0,0 +1,29 @@ +import win32com.client +import time + +def get_pnp_devices(): + wmi = win32com.client.GetObject("winmgmts:") + pnp_devices = wmi.InstancesOf("Win32_PnPEntity") + return {device.DeviceID: device.Name for device in pnp_devices} + +if __name__ == '__main__': + devices_before = get_pnp_devices() + print("Waiting for PnP device change...") + while True: + time.sleep(1) # Adding a delay to reduce CPU usage + devices_now = get_pnp_devices() + + new_devices = devices_now.keys() - devices_before.keys() + removed_devices = devices_before.keys() - devices_now.keys() + + if new_devices: + print("New PnP devices detected:") + for device_id in new_devices: + print(devices_now[device_id]) + + if removed_devices: + print("PnP devices removed:") + for device_id in removed_devices: + print(devices_before[device_id]) + + devices_before = devices_now +\ No newline at end of file diff --git a/requirements.txt b/requirements.txt Binary files differ.