简体   繁体   English

如何使用批处理脚本检查特定的USB设备(而非存储设备)是否连接到Windows?

[英]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. 我想在Windows启动时仅在连接特定USB设备时运行脚本。

Is there anyway to achieve this in batch scripting? 无论如何,是否可以通过批处理脚本来实现这一目标? Or is there any better way? 还是有更好的方法?

get devcon.exe for your platform 为您的平台获取devcon.exe

get identification string of USB device you want to monitor 获取要监视的USB设备的标识字符串

devcon find USB*

than replace xxxx and yyyy strings in following command by your own and run it. 而不是自己替换以下命令中的xxxx和yyyy字符串并运行它。 If errorlevel 0, at least one requested device is present. 如果错误级别为0,则至少存在一个请求的设备。 If errorlevel 1, no device is present. 如果错误级别为1,则不存在任何设备。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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