So I finally solved it!
Source of the problem: an Android TV (HiSense model) connected to my network. Yes. A TV caused this issue.
Details:
The root cause is the TV generates random UUIDs for UPNP network discovery every few minutes. That means it poses as a new device. This caused windows to add it to the device list (Device Association Framework, aka DAF) as a new device. This means now 1000s of devices (which is the same device) filled the device tree causing it to enumerate forever. Thus the "deadlock".
TaskManager uses DasHost to enumerate devices for some reason, so that hangs.
Bluetooth relies on device discovery, so that also hangs, and Settings app along with it.
Network discovery in file explorer obviously also needs Device discovery, so that also hangs.
How to solve:
- Open Services App, find "Device Association Service", right-click it, properties and change Startup type to "Disabled". Then Apply and close.
- You can't stop the process from Services, so you need to force kill it. Open ProcessExplorer by Sysinternals as Admin, stop the svchost.exe that is parent to dashost.exe.
- Download PStools by Sysinternals, open an Admin terminal, run:
.\psexec.exe -i -d -s c:\windows\regedit.exe
This will open regedit as SYSTEM user.
- Navigate to:
Computer\HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\DeviceAssociationService\State\Store
You will find hundreds of keys with a DAFUPnPProvider#uuid.... name. You need to delete ALL of these ones (only inside the Store key, nothing else) and not any other prefix. ONLY THE DAFUPnPProvider ones, like so:
Just select the first key, hit delete key, then enter key. Keep doing it till I think WiFiDirect key and Bluetooth device keys remains.
- Reboot. You should now enable (make startup type to Automatic) the service you disabled and it should start working.
- Done :)
BT fixed, TaskManager Fixed, and Network Discovery Fixed.
How I discovered it:
I was just checking the handles of the service and discovered the "Store" key by accident. I checked it and found maybe 300 or so keys. I knew this was an issue with UPnP because of the name of the service. Also I posted an issue before of the TV causing UPnP flood, but didn't think Windows would go for a toss due to this.
Update:
You might also need to check out this key as well:
Computer\HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Enum\SWD\DAFUPnPProvider
It also contains some UPnP discovery keys. There might be more places that I'm not aware of.