2

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?

OskeeHelpMe
  • 21
  • 1
  • 3

2 Answers2

0

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

NOTE: THIS SCRIPT ISN'T MINE, I TOOK IT FROM HERE.

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

Wasif
  • 7,984
  • 2
  • 19
  • 32
ahmedg
  • 146
  • 6
0

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
 Return
Sleep, 500
Click %connectButtonX%, %connectButtonY%

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

Send {Escape}
Brad Turek
  • 117
  • 6
  • 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 03 '21 at 09: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 03 '21 at 11:54
  • I wasn't aware that Win+k went right to the connect screen. – Brad Turek Nov 05 '21 at 20:45