如何使用python在Windows中禁用/启用特定的USB端口?

时间:2018-12-24 12:22:03

标签: python windows

我想在图形窗口中创建一个切换开关,该开关可以使用python在Windows中禁用/启用特定的USB端口,我可以使用哪个外部命令或库?

1 个答案:

答案 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