DeviceCleanupCmd
DeviceCleanupCmd
Commandline tool which removes non present devices from the device tree
which match one of the given patterns.
Works under Window 2000, XP, Vista, Windows 7, 8, 10, 11 and their Server versions
Under x64 edtitions of Windows only the x64 version can remove devices.
Usage:
patterns are device IDs, device classes or friendly names. Wildcards can be used.
Samples:
remove all non present devices whose device IDs begin with HID\VID_045E
DeviceCleanupCmd HID\VID_045E*
remove all non present devices whose device IDs contain VID_045E&PID_1234
DeviceCleanupCmd "*VID_045E&PID_1234*"
(Because of the contained & character the ID must be enclosed in quotation marks.)
remove all non present devices not used for at least one year
DeviceCleanupCmd * -m:1y
The device's 'age' time comes from the write time of the device's registry key
under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum
On some Windows the times are set on startup or recurring for no obvious reason,
so all devices seem to have the same age. On most Windows the time is set when
the device gets active.
Non-PnP devices and 'soft' devices are not deleted because they are not
automatically
re-installed. These are devices whose ID begins with
- HTREE\ROOT\
- ROOT\
- SWD\
- SW\{
If you want to delete them, use a pattern that begins with one of these strings.
Or use the GUI version of DeviceCleanup.
By default a System Restore Point is created before the first device is removed
(provided Windows has a System Restore).
Since Windows 8 only one SRP within 24 hours can be created. For any further the
API
pretends to have created one but did nothing in fact.
This can be overruled by setting the registry value
SystemRestorePointCreationFrequency under
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore to a
minimal
allowed interval in minutes, 0 disables the blocking completely.
When creating a System Restore Point, DeviceCleanup sets this value to 0
temporarily.
If the last device using a certain COM-port is removed then the reservation under
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\COM Name Arbiter
is removed.
Since Windows 10 version 1903 there is a sub-key "Devices" where Windows tries to
keeps track of
COM-ports and their devices. Windows uses this to remove the reservation when a
COM-port device
is uninstalled. Finally after 25 years. Of course Windows does not check for other
devices
which use the same COM port. DeviceCleanup does.
Licence: Freeware
Allowed:
- usage in any environment, including commercial
- include in software products, including commercial
- include on CD/DVD of computer magazines
- making available for download by means of package managers
Not allowed:
- modify any of the files
- offer for download by means of a "downloader" software
Uwe Sieber
Dec 2021