用于启用蓝牙并连接到特定蓝牙设备的 Windows 10 批处理脚本

标签 windows batch-file automation bluetooth

<分区>

我经常在 Galaxy Buds 与手机和电脑之间切换。我发现最简单的方法是关闭一台设备上的蓝牙并进行切换。我想做的只是创建一个打开蓝牙(如果当前关闭)的 Windows 10 批处理脚本,然后连接到我的耳机。有什么简单的解决办法吗?它将为我节省 4 次点击,但我想我会很感激这种便利。

最佳答案

您可以使用 pnputil使用 pnputil 驱动程序服务工具禁用或启用您的蓝牙驱动程序。至于专门通过CMD连接到蓝牙设备,据我所知,我不认为这是可能的,但我相信你可以在powershell中。

(查看C:\Windows\diagnostics\system\Bluetooth下的Bluetooth诊断文件,都是powershell,运行一下,可能会重置驱动,所以应该可以使用部分的代码。)

# scan bluetooth devices
pnputil.exe /enum-devices /class bluetooth

# ... a long list of Bluetooth related items.
# Look for something like: 

Instance ID:                USB\VID_0CF3&PID_E500\5&2a9042b0&0&4
Device Description:         Qualcomm Atheros QCA9377 Bluetooth
Class Name:                 Bluetooth
Class GUID:                 {e0cbf06c-cd8b-4647-bb8a-263b43f0f974}
Manufacturer Name:          Qualcomm Atheros Communications
Status:                     Started
Driver Name:                oem41.inf

# Disable this device:
$ pnputil.exe /disable-device "USB\VID_0CF3&PID_E500\5&2a9042b0&0&4"

Microsoft PnP Utility

Disabling device:          USB\VID_0CF3&PID_E500\5&2a9042b0&0&4
System reboot is needed to complete configuration operations!

记下设备 ID!

重新启用:

$ pnputil.exe /enable-device "BTH\MS_BTHBRB\6&6d7d961&0&1"

Microsoft PnP Utility

Failed to enable device:  BTH\MS_BTHBRB\6&6d7d961&0&1
Device is pending system reboot to complete a previous operation.

不要听,而是进入设置并切换蓝牙开关几次。


更新:2022-11-29

奇怪的是,在重新启动一次后,现在在管理 shell 中运行相同的 pnutils 命令,系统不再要求我重新启动。

为了完整性:

当蓝牙 USB 设备被禁用时。

enter image description here

当启用蓝牙 USB 设备时,但 BT 关闭

enter image description here

当启用蓝牙 USB 设备时,但 BT 切换为ON

enter image description here

关于用于启用蓝牙并连接到特定蓝牙设备的 Windows 10 批处理脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61391776/

相关文章:

java - 无法在 Mongodb 中找到与 java 中的确切日期匹配的文档

java - 如何监控Windows 7中大内存页的JVM使用情况?

windows - Linux 与 Windows 中的文件权限

windows - 在哪里可以下载 PostgreSQL 8.0.2 Windows 安装程序二进制文件?

windows - 为什么需要 IP_MULTICAST_IF 和 IPV6_MULTICAST_IF?

python 动态回答终端提示是/否

windows - 如何从批处理文件 (Windows) 向文本文件添加行号

batch-file - 批处理文件播放列表随机排序

loops - 批处理文件遍历子文件夹并将子文件夹名称用作变量

java - Selenium HtmlUnitDriver 程序中捕获的 SocketException