python - 如何使用 python 在 Windows 中禁用/启用特定的 USB 端口?
问题描述
我想在图形窗口中创建一个切换开关,可以使用 python 禁用/启用 Windows 中的特定 USB 端口,我可以使用哪个外部命令或库?
解决方案
使用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
推荐阅读
- prolog - PROLOG - 检查文件是否存在
- c# - 如何在 C# 中解析来自 GSM 调制解调器的短信
- git - git:解决分支内的提交?
- node.js - 使用 merge2 -npm 流式传输多个任务时在 Gulp 中出现 TypeError
- android - 如何在 Jetpack 中使用导航启动第二个活动
- .net - 在哪里放置 POCO 验证 - N 层架构
- vba - word中的幻影风格
- frameworks - 在 Microsoft Bot Framework 中取消或退出 PromptDialog.Choice 流
- javascript - 如何更改具有相同功能的make js按钮l,例如jsf-button?
- swift - CTFontGetAdvancesForGlyphs 是如何工作的?