Hi again, Andrius! Thanks for the detailed follow up! Here are few more steps to try.
Automate Device Cleanup with a Scheduled Task:
Since running the CMD version of Device Cleanup Tool takes a long time on your system, you could automate the cleanup process using a scheduled task to run periodically.
> Create a batch file to remove non-present devices by running the Device Cleanup Tool's CMD version.
> Schedule it to run at a specific time (e.g., daily or weekly) using Task Scheduler.
> This method would help automate the cleanup process without you needing to run it manually each time.
Using PowerShell for Bulk Removal
If CMD doesn’t work, you can use PowerShell to automate the removal of COM ports. Here’s a script that can help:
$comPorts = Get-WmiObject Win32_SerialPort | Where-Object { $_.DeviceID -match "COM" }
foreach ($port in $comPorts) {
$port.PSBase.Delete()
}
This will find and delete all the COM ports listed in the system. You can save this script as a .ps1 file and run it with PowerShell as Administrator.
Forgetting Unused Devices Automatically:
Unfortunately, Windows doesn't provide an out-of-the-box option to forget unused devices after a set time, but you can reduce the amount of remembered devices by:
> Disabling Auto-Enumeration of Devices: By adjusting device installation settings:
> Open Device Installation Settings (type Device Installation Settings in the Start menu).
> Choose No (your device might not work as expected).
> This will prevent Windows from automatically remembering newly plugged devices, although it won’t affect already saved ones.
Please give these steps a try and let me know if they help. If you run into more issues, feel free to provide further details, and I'll continue assisting you!
Best,