How to Programmatically Disable Particular USB

Updated Feb 6, 2024

Environment

Software

  • LabVIEW

Operating System

  • Windows

Other

  • PnPUtil.exe

There are USB DAQs that will output 5V from the digital port when the device is powered up and it is unable to change this behavior. When this kind of DAQ device meets an application that will turn a warning when detecting device output 5V during application start, the application could be unable to work properly. This article will introduce a way to programmatically disable USB devices.

1. Try opening the command prompt with administrator privileges and execute the below command to get the USB Instance ID from the result of the command:
pnputil /enum-devices
2. After getting the USB Instance ID, you can use the command prompt to disable or enable a particular USB using the commands by replacing the Instance ID of your USB with the blue color command.
To disable the USB, use the below command:
pnputil /disable-device "USB\VID_0424&PID_2807\5&2847cd3e&0&2"
To enable the USB, use the below command:
pnputil /enable-device "USB\VID_0424&PID_2807\5&2847cd3e&0&2"
Below is the execution result in the command prompt.
CMD_Result
3. After confirming you can execute the code in the command prompt, opening the LabVIEW with administrator privileges, use System Exec.vi and execute the command below:
cmd /c C:\Windows\Sysnative\PnPUtil.exe /disable-device "USB\VID_0424&PID_2807\5&2847cd3e&0&2" 
Remark: Remember to change the purple color word and the blue color words in the command to fit your requirements.
Example_Code
 

You should be able to verify the condition of the USB in Windows Device Manager.