Black God

How to plug-in and plug-out USB device through command line in Windows

This post talks about how to plug-in and plug-out a USB device through command line without doing it physically. This helps to eliminate wear and tear of connector during development cycle. You need devcon.exe, a utility provided by Microsoft for debug and development purpose. It is a command line tool equivalent to GUI based Device Manager in Windows. You can get more information and download it from here. This tool is highly powerful, apart from this task, it can replace the Device Manager in Windows from command line.

One time setup:

1. Copy the downloaded devcon.exe to your system path such as C:\WINDOWS or C:\WINNT

2. Don’t connect your USB device now. Enter “devcon find @usb\*” in command prompt.

C:\BlackGod>devcon find @usb\*
USB\ROOT_HUB\4&13C1814E&0                                   : USB Root Hub
USB\ROOT_HUB\4&1ADC725&0                                    : USB Root Hub
USB\ROOT_HUB\4&1E4840BB&0                                   : USB Root Hub
USB\ROOT_HUB\4&38A6C532&0                                   : USB Root Hub
USB\ROOT_HUB\4&3AB45E4D&0                                   : USB Root Hub
USB\ROOT_HUB20\4&27254C1C&0                                 : USB 2.0 Root Hub
USB\ROOT_HUB20\4&327F519F&0                                 : USB 2.0 Root Hub
USB\VID_413C&PID_2005\5&19D1CE61&0&1                        : USB Human Interfac
e Device
USB\VID_413C&PID_3200\5&2377F6EF&0&2                        : USB Human Interfac
e Device
9 matching device(s) found.

Just note down the output on screen.

3. Now connect your USB device. In this example I am connecting my USB Memory card reader. Now issue command “devcon find @usb\*” again to identify the product id of the device. In the below output, an additional line (in green) identifies my device and it shows my product id as “PID_6230″. Just note down your product id also this way.

C:\BlackGod>devcon find @usb\*
USB\ROOT_HUB\4&13C1814E&0                                   : USB Root Hub
USB\ROOT_HUB\4&1ADC725&0                                    : USB Root Hub
USB\ROOT_HUB\4&1E4840BB&0                                   : USB Root Hub
USB\ROOT_HUB\4&38A6C532&0                                   : USB Root Hub
USB\ROOT_HUB\4&3AB45E4D&0                                   : USB Root Hub
USB\ROOT_HUB20\4&27254C1C&0                                 : USB 2.0 Root Hub
USB\ROOT_HUB20\4&327F519F&0                                 : USB 2.0 Root Hub
USB\VID_0CF2&PID_6230\606569746801                          : USB Mass Storage D
evice

USB\VID_413C&PID_2005\5&19D1CE61&0&1                        : USB Human Interfac
e Device
USB\VID_413C&PID_3200\5&2377F6EF&0&2                        : USB Human Interfac
e Device
10 matching device(s) found.

Now we are set ready. You can always connect your USB device in USB port of your machine.

Plug-out command:

Run “devcon disable *PID_6230” in command line. You use your product id instead of PID_6230 in my command. This will disable my device. This command is equivalent to plug-out of USB device.

Plug-in command:

Run “devcon enable *PID_6230” in command line. You use your product id instead of PID_6230 in my command. This will enable your device. This command is equivalent to plug-in of USB device.

You can create shortcut for enable and disable commands if necessary or free to make batch file.

1 comment for “How to plug-in and plug-out USB device through command line in Windows

  1. Abce
    November 16, 2011 at 11:21 pm

    Thanks for the tip, it works however in my case devcon said:

    USBVID_125F&PID_A94A105000009897: Disabled on reboot
    Not all of 1 device(s) disabled, at least one requires reboot to complete the operation.

Leave a Reply

Your email address will not be published. Required fields are marked *