Computer troubleshooting series #4: Remove devices from Windows 10 "Cast to Device" right-click menu

2024-05-01 - Reading time: 11 minutes

Crosspost: https://answers.microsoft.com/en-us/windows/forum/windows_10-hardware/remove-certain-bluetooth-devices-from-cast-to/78e33507-3ba1-4d4e-bf45-c6f7d222c5ef

Problem Description

Unwanted devices in the menu

As shown in image , there are devices called "HUAWEI FreeBuds Studio" and "Beats Solo3". These devices were bluetooth headphones I have owned years ago, and I stopped using them for at least a year. I am very confident that either of these devices are located at least 5,000 miles away from my computer.

I have made the following effort to eliminate them:

  • Delete whatever such entry from "Settings" app ->"Devices"
  • Delete whatever such entry, either hidden or not, from "Device Manager" (devmgmt.msc)
  • Delete whatever such entry from "Control Panel" -> "Devices and Printers", and elsewhere if I can find them
  • Search for these names in "Registry Editor" and delete results where appropriate
  • Search for these names in the system drive, from text and non-text files, and delete results where appropriate
  • Search for these names in the system drive from text files, learn an association between device names and GUIDs, then search for these GUIDs in Registry Editor and delete results where appropriate
  • Search for binary encoded strings of these names from REG_BINARY records in Registry Editor
  • Clear Network and Sharing Center cache and reset Network settings as instructed by Microsoft Community agent
  • Apply quality and driver updates, clear caches and restart the computer.

At this point, I can not find any apparent trace of the existence of these devices on my computer, yet the Cast to Device menu still displays them. To the extent of my imagination, I have no idea what I should do next, other than recklessly decompiling %system32%\playtomenu.dll.

I am running a 64-bit Windows 10 Pro, Version 22H2 Build 19045. My device is a Surface Laptop Studio i7/32GB/1TB version, and my Bluetooth adapter is built-in.

I would really, really appreciate it if you can give me any advice on how to remove those devices from the menu, without disabling the menu itself.

However, I do not welcome answers that ask me to run antivirus, check Windows update, use Windows troubleshooters, run sfc /scannow or dism /online /cleanup-image /restorehealth, or re-install the OS. If you are tempted to reply with one of these low-effort low-value template answers, please kindly don't.

Detour

  1. I used Sysinternals Procexp to inspect strings in playtomenu.dll and found this thing Windows.Media.Casting.CastingDevice.
  2. I googled it and found out that it's a part of the WinRT API.
  3. I downloaded the sample code and opened with my Visual Studio 2015.
  4. VS2015 prompted about the absence of UWP development features, so I tried to install it.
  5. The installer silently crashes after displaying the splash.
  6. I looked into the log files and found this thing The type initializer for 'System.Windows.Media.FontFamily' threw an exception..
  7. I googled it and found this Microsoft document.
  8. I tried deleting a few fonts and it did not work.
  9. I googled about how to uninstall VS without using the installer and found this Microsoft document, which directed me to this uninstaller tool.
  10. I uninstalled VS2015 and installed VS2022, and reloaded the sample project.
  11. The program threw an EEFileLoadException. I googled it and I was told this is due to a missing dependency, but I can never figure out what it is.
  12. Fuck UWP, I don't like that idea anyway. I started over with a .NET console application.
  13. I found this and this to configure my .NET application to use WinRT APIs.
  14. I used this code to retrieve what playtomenu.dll was probably seeing,
using System;
using System.Threading;
using Windows.Media.Casting;
using Windows.Devices.Enumeration;
using Windows.Foundation;
using System.Collections.Generic;

namespace ConsoleApp1
{
  internal class Program
  {
    static int Main(string[] args)
    {
      String query = CastingDevice.GetDeviceSelector(CastingPlaybackTypes.Audio);
      Console.WriteLine(query);

      IAsyncOperation<DeviceInformationCollection> find = DeviceInformation.FindAllAsync(query);

      while (find.Status != AsyncStatus.Completed)
      {
        Thread.Sleep(1000);
      } 

      DeviceInformationCollection list = find.GetResults();

      foreach (DeviceInformation dev in list) {
        Console.WriteLine(dev.Name);
        Console.WriteLine("  " + dev.Id);
        Console.WriteLine("  " + dev.Kind);
        foreach (KeyValuePair<String, Object> kvp in dev.Properties)
        {
          Console.WriteLine("  " + kvp.Key);
        }
        Console.WriteLine("");
      }

      while (true) Console.ReadKey();
      return 0;
    }
  }
}

which gave me this result:

HUAWEI FreeBuds Studio
  {53E4938F-5210-5EC5-903F-71A16498D056}
  AssociationEndpointContainer
    System.ItemNameDisplay
    System.Devices.DeviceInstanceId
    System.Devices.Icon
    System.Devices.GlyphIcon
    System.Devices.InterfaceEnabled
    System.Devices.IsDefault
    System.Devices.PhysicalDeviceLocation
    System.Devices.ContainerId

Beats Solo3
  {29C5D8F0-7D73-510D-97F7-B65A0747C499}
  AssociationEndpointContainer
    System.ItemNameDisplay
    System.Devices.DeviceInstanceId
    System.Devices.Icon
    System.Devices.GlyphIcon
    System.Devices.InterfaceEnabled
    System.Devices.IsDefault
    System.Devices.PhysicalDeviceLocation
    System.Devices.ContainerId

Beats Solo3
  {4F973908-62D5-5FCE-BFB2-3FA5B2CDF055}
  AssociationEndpointContainer
    System.ItemNameDisplay
    System.Devices.DeviceInstanceId
    System.Devices.Icon
    System.Devices.GlyphIcon
    System.Devices.InterfaceEnabled
    System.Devices.IsDefault
    System.Devices.PhysicalDeviceLocation
    System.Devices.ContainerId
  1. I further explored and wondered why DeviceInstanceId, PhysicalDeviceLocation, and ContainerId were all null for all these devices.
  2. I searched these GUIDs in registry editor and nothing was there.
  3. I printed out the string results of CastingDevice.GetDeviceSelector(CastingPlaybackTypes.Audio), which looks like this (formatted):
(System.Devices.DevObjectType:=6) AND
(
    (System.Devices.AepContainer.ProtocolIds:~~"{E0CBF06C-CD8B-4647-BB8A-263B43F0F974}"
    AND System.Devices.AepContainer.SupportsAudio:=System.StructuredQueryType.Boolean#True
    AND System.Devices.AepContainer.SupportsRendering:=System.StructuredQueryType.Boolean#True)
OR 
    ((System.Devices.AepContainer.ProtocolIds:~~"{0E261DE4-12F0-46E6-91BA-428607CCEF64}"
    AND System.Devices.AepContainer.Categories:~~Multimedia.DMR)
    AND System.Devices.AepContainer.SupportsAudio:=System.StructuredQueryType.Boolean#True)
OR 
    (System.Devices.AepContainer.ProtocolIds:~~"{0407D24E-53DE-4C9A-9BA1-9CED54641188}"
    AND System.Devices.AepContainer.IsPresent:=System.StructuredQueryType.Boolean#True)
)
  1. I searched E0CBF06C-CD8B-4647-BB8A-263B43F0F974 in registry editor.
  2. I found this thing:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Device Association Framework\InboxProviders\Bluetooth

dafBth

  1. I restarted the Device Association Service in Services. (Yeah, I'm pretty much crazy now)
  2. I exported the registry key and it looked like this:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Device Association Framework\InboxProviders\Bluetooth]
"AllowReassociation"=dword:00000001
"Capabilities"=dword:0000028d
"CLSID"="{4aa383d6-337a-43d3-a3fa-c14b26004130}"
"DllPath"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,\
  74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,64,\
  00,61,00,66,00,42,00,74,00,68,00,2e,00,64,00,6c,00,6c,00,00,00
"ImpersonateCaller"=dword:00000001
"PropertyRank"=dword:00000032
"ProtocolId"="{e0cbf06c-cd8b-4647-bb8a-263b43f0f974}"
"SecurityContext"=dword:00000000
  1. I stared at the "DllPath" part and realized that it was a null-byte-separated ASCII string.
  2. I recalled trying searching for such binary content when I first tried to resolve this problem.
  3. I wondered why it didn't work and out of desperation, I decided to try it again.

Solution

It turned out that,

Search for binary encoded strings of these names from REG_BINARY records in Registry Editor

is actually the correct answer. I don't know why it didn't work when I tried first.

I used NirSoft's RegScanner because it supports searching for binary values. The device names are stored in an encoded format where for any ASCII character, the value is its ASCII value followed by a null byte. For example, to locate my FreeBuds Studio as shown in the first image, I searched for 46 00 72 00 65 00 65 00 42.

Byte value: 46 00 72 00 65 00 65 00 42
ASCII char:  F     r     e     e     B

Scan options dialog

The search gave me two registry paths:

Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Device Association Framework\Store\Bluetooth#*
Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\DeviceAssociationService\State\Store\Bluetooth#*

By examining all such registry keys and deleting them, I was able to get rid of these devices.

results

At last

I closed all browser tabs I opened for solving this problem and had a cyber orgasm.

closing tabs

May 01, 2024

Tianjian.Hu

Record of my genius ideas and mental disorders.