I'm at my wits' end right now.

I'm on the latest version of Windows 10 and I just want to run a script to connect/disconnect to my Bluetooth headphones when executed. I've looked at a couple other posts on the website, namely this one, which all suggested to use this. I actually had it working for a while for about an hour, however, it suddenly starting throwing up System Error 87 after a while (and I hadn't changed anything, it just stopped working).

Are there any alternative ways to accomplish this or will I just be stuck having to click three extra buttons?

  • Have you figured this out, possibly with AHK? I simply want to turn on bluetooth with AHK... Apr 26 '21 at 2:15

Try this one: (You'll need Administrative Privilege)

$device = Get-PnpDevice | Where-Object {$_.Class -eq "Bluetooth" -and $_.FriendlyName -eq "FriendlyDeviceName"}
Disable-PnpDevice -InstanceId $device.InstanceId -Confirm:$false
Start-Sleep -Seconds 10
Enable-PnpDevice -InstanceId >$device.InstanceId -Confirm:$false


Additionally, you can use these tools: http://bluetoothinstaller.com/bluetooth-command-line-tools/


I had this same problem and it looks like there's already a shortcut for it:

Win + A then click Connect

Keying the shortcut and clicking connect and choosing my headphones; then they connect.

However, one could abbreviate it further by creating a tricky AutoHotkey script to make it all happen with one keystroke.

#SingleInstance, force
CoordMode, Mouse, Screen

^!c:: ; Press Ctrl + Alt + C to start

; You'll need to find your Connect button's Screen coordinates with Window Spy. 
connectButtonX = 1120
connectButtonY = 570

; You'll need to find your device entry's Screen coordinates with Window Spy.
deviceEntryX = 1130
deviceEntryY = 240

Send #a ;Win + A

WinWaitActive, ahk_exe Shellexperiencehost.exe,, 5
If ErrorLevel
Sleep, 500
Click %connectButtonX%, %connectButtonY%

WinWaitActive, ahk_exe Shellexperiencehost.exe,, 5
If ErrorLevel
Sleep, 1200
Click %deviceEntryX%, %deviceEntryY%

Send {Escape}
  • Ugh. As some who has used AHK for other purposes, I would hope that a better way can be done than hard-coding to a specific screen resolution. And making this and then holding Ctrl-Alt-C seems more convoluted than holding the Start button and pressing K, which I think is just going to be a fastr way for you. If you want to support a situation without a Start button on a keyboard (maybe for remote connections), maybe AHK can simulate holding down the start button and pressking K.
    – TOOGAM
    Nov 3 '21 at 9:43
  • (To clarify, I'm suggesting that Win+k is simpler than Win+a and then Connect. I'm not suggesting that removes the need to then click on something that represents the individual device.)
    – TOOGAM
    Nov 3 '21 at 11:54
  • I wasn't aware that Win+k went right to the connect screen.
    – Brad Turek
    Nov 5 '21 at 20:45

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.