这是我使用 cmd 打开/关闭蓝牙的解决方案:
@echo off
setlocal enabledelayedexpansion
set "bluetoothStatus="
set "command="
:: Check current Bluetooth status
for /f "tokens=3 delims=: " %%a in ('reg query "HKLM\SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Radio Management" /v "Enable" ^| find "Enable"') do (
set "bluetoothStatus=%%a"
)
if /i "%bluetoothStatus%"=="0x1" (
set "command=stop"
) else (
set "command=start"
)
:: Execute the command
if /i "%command%"=="start" (
echo Turning on Bluetooth...
net start bthserv
) else (
echo Turning off Bluetooth...
net stop bthserv
)
:: Display the updated Bluetooth status
for /f "tokens=3 delims=: " %%a in ('reg query "HKLM\SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Radio Management" /v "Enable" ^| find "Enable"') do (
set "bluetoothStatus=%%a"
)
if /i "%bluetoothStatus%"=="0x1" (
echo Bluetooth is now ON.
) else (
echo Bluetooth is now OFF.
)
endlocal
将上述代码保存在扩展名为 .bat 的文件中,例如 laosBlue.bat。要使用它,请双击批处理文件,它将在开启和关闭之间切换蓝牙状态。请注意,修改注册表和停止服务可能需要管理员权限。如果需要,请确保以管理员身份运行批处理文件。
请记住,使用注册表和服务可能会产生后果,因此使用此脚本需要您自担风险。