How can I toggle Bluetooth on and off via a shortcut or script in Windows 8.1?

7

3

Before upgrading to Windows 8.1 I used the bluetooth icon in the notifications area to turn bluetooth on and off. Now, in Windows 8.1 it requires about 6 clicks to get this job done through the new metro UI. See How to turn on/off Bluetooth on Windows 8.1 for the slow way to get this job done.

I would like to go back to being able to toggle my bluetooth in a couple of clicks without having to leave my desktop. Can it be done?

i did not pay the royalties

Posted 2014-12-10T00:58:11.157

Reputation: 292

Answers

3

Yes, it can be done. I'm not sure if this is the easiest way, but it works

Creating a batch file

  1. Create a new .bat file and call it something like bluetooth.bat
  2. Inside the file, paste the following script

The script checks if the Bluetooth Support Service (bthserv) is running.

If running, it stops the service. If stopped, it starts the service.

@echo off

for /F "tokens=3 delims=: " %%H in ('sc query "bthserv" ^| findstr "STATE"') do (
  if /I "%%H" NEQ "RUNNING" (
   net start "bthserv"
  ) else if /I "%%H" NEQ "STOPPED" (
   net stop "bthserv"
  )
)
  1. Save the .bat and then run it as an Administrator

Execution

If the service is stopped, you'll see:

If the service is running, you'll see:

If you want to stop the window from automatically closing, add a new line with @pause to the bottom of your script. Then you'll be prompted with Press any key to continue . . ..

Edit from comments:

The first time you use the batch file, add @pause to the bottom of the script and select y for any prompts that appear. Then test it out once more to make sure it's working as intended. If it is, you can remove @pause.

Always run as Administrator

If you want, which I assume you will, for the .bat to always run as Admin, do the following:

  1. Right click on your bluetooth.bat and click "Send to" -> "Desktop (Create Shortcut)

  1. Right click on the shortcut, click properties, then find the "Shortcut" tab at the top. Click "Advanced"

  1. Select "Run as Administrator"

  1. From now on, run the shortcut instead! All done.

Insane

Posted 2014-12-10T00:58:11.157

Reputation: 2 599

1This does not work on Windows 8.1. – Ahmed – 2015-10-23T03:40:30.390

@Ahmed What about it doesn't work? AFAIK the service name is the same. What error do you get, in specific? – Insane – 2015-10-23T03:41:22.063

No error, just after i ran the .bat file as administrator, my bluetooth is still on and my bluetooth speaker is still connected to computer. – Ahmed – 2015-10-23T03:44:01.063

Add @pause at the end of the script to see the error, to prevent the .BAT from automatically closing. Paste the output. – Insane – 2015-10-23T03:45:27.830

The following services are dependent on the Bluetooth Support Service service. Stopping the Bluetooth Support Service service will also stop these services.

Bluetooth Handsfree Service

Do you want to continue this operation? (Y/N) [N]: y The Bluetooth Handsfree Service service is stopping. The Bluetooth Handsfree Service service was stopped successfully.

The Bluetooth Support Service service is stopping. The Bluetooth Support Service service was stopped successfully. – Ahmed – 2015-10-23T04:07:39.853

1I ran it again and it gave the appropriate turning "off" and turning "on" if run again. – Ahmed – 2015-10-23T04:09:38.350

Ah so it works now? Seems like you had to select yes for that initial. If it works as intended now I'll edit my answer with what you found. – Insane – 2015-10-23T04:10:27.320

1Well, it's not doing anything. My bluetooth is still connected and playing music. Nothing seems to be affected. – Ahmed – 2015-10-23T05:05:04.117

@Ahmed Has something to do with the Bluetooth Handsfree Service. Go to services, find the Bluetooth Handsfree Service and grab the actual service name and I'll amend the code to stop and start both services at once. I think that'll fix it. – Insane – 2015-10-23T05:06:51.377

"BthHFSrv" and "bthserv" – Ahmed – 2015-10-23T17:01:57.050