Unable to remove bluetooth device on windows 10

Hello

I am running windows 10 64bit, and have a BeeWi BH100 headphone paired to my PC.

The device was unable to connect and I tried to remove it via the Bluetooth settings menu. It said removed failed at first, but later I was able to remove the device. However the device doesn´t show up as available to be paired and keeps on reappearing each time I turn Bluetooth on and off.

I also tried deleting via device manager, and it again reappears on its own every time I scan for hardware changes or reset my Bluetooth adapter. I have turned my Bluetooth adapter off, and click show hidden devices and tried to delete it, but when I turn the adapter back on it reappears. I tried removing the Bluetooth Enumator, Human interface drivers and AV remote and restart my PC, but it didn´t solve the problem.

I also tried setting Bluetooth services to automatic and log on to Local service, without luck.

There is nothing wrong with my headphones as it connects to my phone without a problem...

Is there anyway to forcefully remove the device and restart the pairing from scratch, as the conventional methods do not remove my device.

 

Question Info


Last updated August 21, 2019 Views 63,600 Applies to:

* Please try a lower page number.

* Please enter only numbers.

* Please try a lower page number.

* Please enter only numbers.

  As a final note: anyone that does know C# is please invited to have a look at my tool's source code and suggest a way to make it easier to use (by listing the BT devices, for example), right now I know that it's a pain to get the BT address manually :(

I created an issue on GitHub for this: https://github.com/lflfm/btRemover/issues/1

Hi LFLFM,

Not a C# programmer, but I've learned a little to take advantage of PowerShell's Add-Type cmdlet's ability to access APIs. I cmae up with the following PowerShell code, but testing is limited to my laptop & the few devices I have. The following should list all paired Bluetooth devices:

    Get-PnpDevice -class Bluetooth|

      ?{$_.HardwareID -match 'DEV_'} |

         select Status, Class, FriendlyName, HardwareID,

            # Extract device address from HardwareID

            @{N='Address';E={[uInt64]('0x{0}' -f $_.HardwareID[0].Substring(12))}}

Can you (and others) test & verify?

Keith

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.

I think I have working PowerShell code! Can others test??

$Source = @"

   [DllImport("BluetoothAPIs.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall)]

   [return: MarshalAs(UnmanagedType.U4)]

   static extern UInt32 BluetoothRemoveDevice(IntPtr pAddress);


   public static UInt32 Unpair(UInt64 BTAddress) {

      GCHandle pinnedAddr = GCHandle.Alloc(BTAddress, GCHandleType.Pinned);

      IntPtr pAddress     = pinnedAddr.AddrOfPinnedObject();

      UInt32 result       = BluetoothRemoveDevice(pAddress);

      pinnedAddr.Free();

      return result;

   }

"@


Function Get-BTDevice {

    Get-PnpDevice -class Bluetooth |

      ?{$_.HardwareID -match 'DEV_'} |

         select Status, Class, FriendlyName, HardwareID,

            # Extract device address from HardwareID

            @{N='Address';E={[uInt64]('0x{0}' -f $_.HardwareID[0].Substring(12))}}

}


################## Execution Begins Here ################


$BTDevices = @(Get-BTDevice) # Force array if null or single item

$BTR = Add-Type -MemberDefinition $Source -Name "BTRemover"  -Namespace "BStuff" -PassThru


Do {

   If ($BTDevices.Count) {

      "`n******** Bluetooth Devices ********`n" | Write-Host

      For ($i=0; $i -lt $BTDevices.Count; $i++) {

         ('{0,5} - {1}' -f ($i+1), $BTDevices[$i].FriendlyName) | Write-Host

      }

      $selected = Read-Host "`nSelect a device to remove (0 to Exit)"

      If ([int]$selected -in 1..$BTDevices.Count) {

         'Removing device: {0}' -f $BTDevices[$Selected-1].FriendlyName | Write-Host

         $Result = $BTR::Unpair($BTDevices[$Selected-1].Address)

         If (!$Result) {"Device removed successfully." | Write-Host}

         Else {"Sorry, an error occured." | Write-Host}

      }

   }

   Else {

      "`n********* No devices foundd ********" | Write-Host

   }

} While (($BTDevices = @(Get-BTDevice)) -and [int]$selected)

Keith

4 people were helped by this reply

·

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.

The script works for me for normal remove, but I don't know if it does for the main problem of this thread as I already solved it.

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.

Tanks for the feedback. I'm pretty confident it would solve the problem as it uses the same API as LFLFM's code.

Keith

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.

Tanks for the feedback. I'm pretty confident it would solve the problem as it uses the same API as LFLFM's code.

Keith

  I've not tried it yet, but I had a look at the code and I'm sure that it will work; since it really is doing exactly the same thing as mine, but easier and better! (since it lists the devices as well AND requires no coding, compiling, IDE; nothing, it will just work in any machine)

Great work Keith!!

  I did actually look into Powershell before I made mine in C#, but I had never used Powershell and my first couple of attempts failed so I gave up and went for C# since I know it a little from small quick fixes like this one :)

  I'll have a better look and test of your script this weekend and then I'll actually replace my solution for yours on Github, if you don't mind.

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.

  I've not tried it yet, but I had a look at the code and I'm sure that it will work; since it really is doing exactly the same thing as mine, but easier and better! (since it lists the devices as well AND requires no coding, compiling, IDE; nothing, it will just work in any machine)

Great work Keith!!

  I did actually look into Powershell before I made mine in C#, but I had never used Powershell and my first couple of attempts failed so I gave up and went for C# since I know it a little from small quick fixes like this one :)

  I'll have a better look and test of your script this weekend and then I'll actually replace my solution for yours on Github, if you don't mind.

Thanks for the freply & feedback. I llook forward to any insight or suggestions you have after a closer look. Of course, you're welcome to post the code on Github. thanks for the inspiration!

Keith

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.

I think I have working PowerShell code! Can others test??

$Source = @"

   [DllImport("BluetoothAPIs.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall)]

   [return: MarshalAs(UnmanagedType.U4)]

   static extern UInt32 BluetoothRemoveDevice(IntPtr pAddress);


   public static UInt32 Unpair(UInt64 BTAddress) {

      GCHandle pinnedAddr = GCHandle.Alloc(BTAddress, GCHandleType.Pinned);

      IntPtr pAddress     = pinnedAddr.AddrOfPinnedObject();

      UInt32 result       = BluetoothRemoveDevice(pAddress);

      pinnedAddr.Free();

      return result;

   }

"@


Function Get-BTDevice {

    Get-PnpDevice -class Bluetooth |

      ?{$_.HardwareID -match 'DEV_'} |

         select Status, Class, FriendlyName, HardwareID,

            # Extract device address from HardwareID

            @{N='Address';E={[uInt64]('0x{0}' -f $_.HardwareID[0].Substring(12))}}

}


################## Execution Begins Here ################


$BTDevices = @(Get-BTDevice) # Force array if null or single item

$BTR = Add-Type -MemberDefinition $Source -Name "BTRemover"  -Namespace "BStuff" -PassThru


Do {

   If ($BTDevices.Count) {

      "`n******** Bluetooth Devices ********`n" | Write-Host

      For ($i=0; $i -lt $BTDevices.Count; $i++) {

         ('{0,5} - {1}' -f ($i+1), $BTDevices[$i].FriendlyName) | Write-Host

      }

      $selected = Read-Host "`nSelect a device to remove (0 to Exit)"

      If ([int]$selected -in 1..$BTDevices.Count) {

         'Removing device: {0}' -f $BTDevices[$Selected-1].FriendlyName | Write-Host

         $Result = $BTR::Unpair($BTDevices[$Selected-1].Address)

         If (!$Result) {"Device removed successfully." | Write-Host}

         Else {"Sorry, an error occured." | Write-Host}

      }

   }

   Else {

      "`n********* No devices foundd ********" | Write-Host

   }

} While (($BTDevices = @(Get-BTDevice)) -and [int]$selected)

Keith

Well what do you know, 5 months later and again for seemingly no reason whatsoever the same bug occurs on my laptop. My bluetooth speaker is once again paired but refuses to connect, and automagically shows up again shortly after I try removing it. I've been keeping an eye on the thread, perfect timing to test out this script.

In short, it works perfectly. Just dropped it into powershell, hit enter, chose the device, it successfully unpaired it and then I closed powershell and went through the pairing procedure again. Great work @Kieth, this should be marked as the answer for future searchers.

2 people were helped by this reply

·

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.

Thanks, Xzion, and thanks for teh feedback.

Keith

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.

I think I have working PowerShell code! Can others test??

$Source = @"

   [DllImport("BluetoothAPIs.dll", SetLastError = true, CallingConvention = CallingConvention.StdCall)]

   [return: MarshalAs(UnmanagedType.U4)]

   static extern UInt32 BluetoothRemoveDevice(IntPtr pAddress);


   public static UInt32 Unpair(UInt64 BTAddress) {

      GCHandle pinnedAddr = GCHandle.Alloc(BTAddress, GCHandleType.Pinned);

      IntPtr pAddress     = pinnedAddr.AddrOfPinnedObject();

      UInt32 result       = BluetoothRemoveDevice(pAddress);

      pinnedAddr.Free();

      return result;

   }

"@


Function Get-BTDevice {

    Get-PnpDevice -class Bluetooth |

      ?{$_.HardwareID -match 'DEV_'} |

         select Status, Class, FriendlyName, HardwareID,

            # Extract device address from HardwareID

            @{N='Address';E={[uInt64]('0x{0}' -f $_.HardwareID[0].Substring(12))}}

}


################## Execution Begins Here ################


$BTDevices = @(Get-BTDevice) # Force array if null or single item

$BTR = Add-Type -MemberDefinition $Source -Name "BTRemover"  -Namespace "BStuff" -PassThru


Do {

   If ($BTDevices.Count) {

      "`n******** Bluetooth Devices ********`n" | Write-Host

      For ($i=0; $i -lt $BTDevices.Count; $i++) {

         ('{0,5} - {1}' -f ($i+1), $BTDevices[$i].FriendlyName) | Write-Host

      }

      $selected = Read-Host "`nSelect a device to remove (0 to Exit)"

      If ([int]$selected -in 1..$BTDevices.Count) {

         'Removing device: {0}' -f $BTDevices[$Selected-1].FriendlyName | Write-Host

         $Result = $BTR::Unpair($BTDevices[$Selected-1].Address)

         If (!$Result) {"Device removed successfully." | Write-Host}

         Else {"Sorry, an error occured." | Write-Host}

      }

   }

   Else {

      "`n********* No devices foundd ********" | Write-Host

   }

} While (($BTDevices = @(Get-BTDevice)) -and [int]$selected)

Keith

I have a similar problem to many others, but with my Xbox One bluetooth controller. I hadn't used it for a few weeks, but wanted to play a game last Friday, only to find that no matter what I did, I couldn't connect the controller.

I did the exact same thing many others above me have done - removed from device manager, removed from registry, uninstalled and reinstalled the bluetooth drivers, but nothing would work. Every time I turned my bluetooth off and back on, the controller would magically appear again in the device list, and yet it would not connect.

I stumbled on this thread today while looking for solutions and came across this by Keith. Given I'd tried everything else I could think of, I thought I'd give it a try, but not holding out much confidence. Imagine my surprise then, when it worked! It's so easy to do as well - I just copied and pasted the text into PowerShell and it found my Xbox controller, so I chose to remove it. Turned my bluetooth off and back on, and to my surprise the Xbox controller didn't reappear as I expected to, so I tried to pair it again and it was picked up quickly, and is now working like a dream, no more cables for me!

If it's ok by Keith, i would like to place a copy of this on my desktop in a notepad file for future use, because seeing that Microsoft haven't yet fixed it, I do expect to be needing this again.

Thank you very much for your help. As I'm not a coder it's definitely not something i'd be able to do myself, but it's certainly a more elegant and simple way of solving bluetooth issues without needing to download extra software, which is may compromise security.

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.

You're welcome, Scoota. Thanks for the feedback. Of course you can save the code. If you save it with a .ps1 extension, it will still open in Notepad when double-clicked, but you'll have a right-click option to run in PowerShell.

Keith

2 people were helped by this reply

·

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.

* Please try a lower page number.

* Please enter only numbers.

* Please try a lower page number.

* Please enter only numbers.