3

Here it is my solution to turn bluetooth on/off using 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

Save the above code in a file with a .bat extension, such as laosBlue.bat. To use it, double-click on the batch file, and it will toggle the Bluetooth status between on and off. Please note that modifying the registry and stopping services may require administrative privileges. Make sure to run the batch file as an administrator if needed.

Remember that working with the registry and services can have consequences, so use this script at your own risk.

Gantendo
  • 4,915

0 Answers0