简体   繁体   中英

How can I check if specific USB device(not storage device) is connected to Windows with batch scripting?

I would like to run my script at Windows startup, only when a specific USB device is connected.

Is there anyway to achieve this in batch scripting? Or is there any better way?

get devcon.exe for your platform

get identification string of USB device you want to monitor

devcon find USB*

than replace xxxx and yyyy strings in following command by your own and run it. If errorlevel 0, at least one requested device is present. If errorlevel 1, no device is present.

devcon status "USB\VID_xxxx&PID_yyyy" | findstr /C:"matching device(s) found">NUL

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM