23

I have bluetooth headphones which I use to both listen to music from my mobile phone and to listen to videos on my laptop. They cannot be connected to both devices at once (note here), so I have to disconnect from one device before connecting to the next device.

To do this on Windows 7, I have to open Devices and Printers, open my bluetooth headphones, and click on the Connect/Disconnect button. I'd love to be able to run a script that triggers that Connect/Disconnect button. That way I could have a shortcut on the desktop or add a keyboard shortcut.

I've streamlined it somewhat by creating a shortcut to the bluetooth heaphones window (in Devices and Printers, right click on your bluetooth device and choose Create Shortcut). But it would be good to streamline further.

4
  • 2
    Yes. My computer does not have Bluetooth capabilities, but you can use AutoHotkey to automate the process. See my answer here for ideas: superuser.com/questions/403620/…
    – iglvzx
    Apr 4, 2012 at 0:37
  • Thanks, good idea. I 'll try it out when I have a spare minute.
    – David Cook
    Apr 16, 2012 at 1:22
  • @DavidCook Let us know if you get it sorted out, I'd love to grab a copy of that script. Jun 30, 2016 at 16:45
  • Sorry @Big, I don't think I ever sorted it out. Glad you found a solution.
    – David Cook
    Jul 22, 2016 at 3:46

2 Answers 2

9

As it turns out, once all services in use by a device get disabled, device gets released and disconnected by Windows automatically. In my example case below for WH-1000XM3 these are voice and music, and most headphones will work the same way. This will of course depend on device in use.

You will need Bluetooth Command Line Tools.

Voice is actually the hands free service (HFP) and music is just an audio sink (A2DP). Service identifiers will be necessary and they can be discovered through the usage of btdiscovery command from the package above, or via the list of Bluetooth services. HFP voice is 111e, A2DP music is 110b.

Per btcom command line help:

Usage:

btcom {-c|-r} {-bBluetoothAddress | -nFriendlyName} [-s{sp|dun|GUID|UUID}]

 -c  Create association between COM port and a remote service (Enable non-COM service).
 -r  Remove association between COM port and a remote service (Disable non-COM service).
 -s  Remote service to use (Default is Serial Port Service)
 -b  Bluetooth address of remote device in (XX:XX:XX:XX:XX:XX) format. 
 -n  Friendly name of remote device.

To disconnect the device, issue the following (only works when run as administrator in my case, using Windows 10 1809 (17763.437)):

"C:\Program Files (x86)\Bluetooth Command Line Tools\bin\btcom" -n "WH-1000XM3" -r -s111e
"C:\Program Files (x86)\Bluetooth Command Line Tools\bin\btcom" -n "WH-1000XM3" -r -s110b

To connect again, issue the same with -c instead of -r. This works for other devices, not just headphones, as long as all services/profiles connected to by Windows get disabled/enabled.

Note: using -n <friendly name> is much slower than using -b <address> due to performing Bluetooth discovery.

8
  • Hey! After I use -r to disconnect, connecting manually from settings doesn't work. The "Connect" button doesn't show up and connecting through the connect action panel (Win+K) says "Couldn't connect". Using -c seems to work. Do you know why? Do you know how I can keep the usual functionality when using this?
    – Faboor
    Oct 6, 2020 at 19:35
  • @Faboor It's because services get disabled on the device, and if there are no services to connect to, Windows won't let you connect. After issuing -r, you will note that in Control Panel > Hardware and Sound > Devices and Printers, if you select your BT device and check its Properties > Services, checkboxes for these services are unchecked. -c basically checks them back again, enabling these services and thus allowing connections.
    – MarcinJ
    Oct 7, 2020 at 20:47
  • Thanks, makes sense. Is there any other way of disconnecting bt rather than disabling the services?
    – Faboor
    Oct 8, 2020 at 11:42
  • 1
    That's the thing, I haven't found any, not on Windows. Unless you use something like AHK or AutoIt to simulate mouse click on that Disconnect button.
    – MarcinJ
    Oct 9, 2020 at 19:55
  • 1
    If you get param -87 issues, see this related question: superuser.com/questions/1585945/…
    – agrath
    Jan 22, 2021 at 8:02
2

I found an a similar question, here is the resolution. https://stackoverflow.com/questions/29724513/automatically-adding-a-bluetooth-device-in-windows-8

@ECHO OFF
if exist toggle.txt goto :2
btpair -u
C:\NIRCMD\NIRCMDC setdefaultsounddevice "CompSpeak" 1
C:\NIRCMD\NIRCMDC setdefaultsounddevice "CompSpeak" 2

echo toggle>>toggle.txt

exit
:2
btpair -n"[Samsung] AirTrack" -p0000
C:\NIRCMD\NIRCMDC setdefaultsounddevice "Headphones" 1
C:\NIRCMD\NIRCMDC setdefaultsounddevice "Headphones" 2

del toggle.txt /q

exit

OP said that he was getting a pop up message box, but he is also on windows 8 so that might be unique to his setup.

1
  • It has some dependencies to nircmd and btpair though...
    – ixe013
    Sep 23, 2021 at 13:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.