尽管注册表中没有条目,但无法删除蓝牙设备

尽管注册表中没有条目,但无法删除蓝牙设备

我有一台运行 Windows 10 的机器。

我正在尝试移除蓝牙设备并重新连接。一开始,当我尝试通过 Windows 设置移除设备时,我收到“移除失败”的消息。当我尝试通过控制面板移除设备时也发生了同样的事情。

我在设备管理器中移除了该设备的驱动程序,但重启后,该设备仍然存在。不过,设备管理器中没有列出该驱动程序。

我采取的最后一步是删除注册表文件中该设备的条目,但重新启动后该设备仍然存在。注册表文件中目前没有条目。我从以下位置删除了它:

HKLM\SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Devices

现在,我在 Windows 设置和控制面板中的“设备和打印机”部分中看到了该设备,但我无法删除任何一个。注册表中没有该设备的条目,也没有该设备的驱动程序。在删除该条目之前,我也没有注册表的备份。

我该如何摆脱这个东西才能重新连接它?这个设备是一副耳机,所以我经常使用它。

答案1

你可以尝试一下电源外壳api的包装器BluetoothRemoveDevice()。将以下代码复制并粘贴到电源外壳窗口,然后按Enter

$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 ################

$BTR       = Add-Type -MemberDefinition $Source -Name "BTRemover"  -Namespace "BStuff" -PassThru
$BTDevices = @(Get-BTDevice) # Force array if null or single item

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 found ********" | Write-Host
   }
} While (($BTDevices = @(Get-BTDevice)) -and [int]$selected)

运行时它将列出蓝牙设备:

PS > . "C:\Users\keith\Sandbox\Bluetooth Removal\removedevice v1.0.ps1"

******** Bluetooth Devices ********

    1 - Chill Out
    2 - LG HBS730

Select a device to remove (0 to Exit):

如果该设备没有列出,我猜测它是一个命名空间工件。

答案2

这对我来说是修复了这个问题:

  1. 打开设备管理器
  2. 展开“蓝牙”。你应该能够看到那里列出的蓝牙设备。
  3. 在设备管理器顶部,打开“查看”菜单并选择“显示隐藏的设备”。启用“显示隐藏的设备”后,您可能会看到一个与您的设备同名且带有淡蓝色图标的其他蓝牙设备(淡蓝色表示它是隐藏设备)。
  4. 右键单击隐藏的设备并选择“卸载设备”。
  5. 现在,转到“设置”>“蓝牙和设备”,您现在就可以删除您的蓝牙设备。

相关内容