c# - 使用 devcon.exe 删除 USB

标签 c# winapi operating-system usb

是否可以使用 devon.exe 按名称删除 USB 大容量存储设备?以下代码用于删除所有设备:

Devcon remove usbstor\*

但现在我想删除一个特定的设备。例如,如果插入 5 个 USB,则 ABCDE F,我现在只想删除 B。我知道实例 ID 用于此目的,但是否可以使用设备名称删除?例如,像

Devcon remove usbstor\B

我试过了,但没用。

最佳答案

您可以通过硬件 ID 删除单个设备。如果您知道该 id,则可以使用删除命令,否则您将必须找出硬件 id。有关详细信息,请参阅帮助:

Devcon Remove Command
Removes devices with the specified hardware or instance ID. Valid only on
the local computer. (To reboot when necesary, Include -r .)
Devcon.exe [-r] remove <id> [<id>...]
Devcon.exe [-r] remove =<class> [<id>...]
<class>      Specifies a device setup class.
Examples of <id>:
 *              - All devices
 ISAPNP\PNP0501 - Hardware ID
 *PNP*          - Hardware ID with wildcards  (* matches anything)
 @ISAPNP\*\*    - Instance ID with wildcards  (@ prefixes instance ID)
 '*PNP0501      - Hardware ID with apostrophe (' prefixes literal match - matches exactly as typed,
                                               including the asterisk.)

关于c# - 使用 devcon.exe 删除 USB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10534983/

相关文章:

c# - 如何继承方法但具有不同的返回类型?

c# - 在运行时添加图像

c - 使用 waitpid 或 sigaction?

c++ - HANDLE_MSG 宏给出 'HANDLE_0xXXXX is undefined'

c++ - 由于 HID 句柄无效(Windows HID C++ API),HidD_* 函数全部失败

c - 线程上下文切换期间程序计数器存储在哪里?

algorithm - O(1) 事件发布给 N 个订阅者

c# - 如何从特定索引到末尾查找列表中的元素?

c# - 如何在 Windows 应用商店应用程序中获取本地主机 IP 地址?

c++ - 使用不带 Unicode 的 ini 文件