I want to create a toggle switch in graphical window that can Disable/Enable specific USB port in windows with python, which external command or library can I use?
Asked
Active
Viewed 1.1k times
1 Answers
3
Use devcon.exe
:
import subprocess
# Fetches the list of all usb devices:
result = subprocess.run(['devcon', 'hwids', '=usb'],
capture_output=True, text=True)
# ... add code to parse the result and get the hwid of the device you want ...
subprocess.run(['devcon', 'disable', parsed_hwid]) # to disable
subprocess.run(['devcon', 'enable', parsed_hwid]) # to enable

nosklo
- 217,122
- 57
- 293
- 297
-
Is that a Windows command? I get *`'devcon' is not recognized as an internal or external command`*. – jww Dec 24 '18 at 12:55
-
@jww please click the link I added to the answer - it explains how to get `devcon.exe` directly from microsoft – nosklo Dec 24 '18 at 13:15