我想在图形窗口中创建一个切换开关,该开关可以使用python在Windows中禁用/启用特定的USB端口,我可以使用哪个外部命令或库?
答案 0 :(得分:1)
使用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