Recently a Microsoft support agent used a tool that I wasn’t familiar with: DevNodeClean.
Basically Windows creates a device in registry for every new device that is connected—even if it’s just a shadow copy created during a Windows backup. To see these, in Device Manager, check View > Show Hidden Devices, then look under Storage volume shadow copies:
Note that some of these, though hidden, may be in use, i.e. they are active shadow copies. To get rid of those that are unused, download DevNodeClean here. From an administrative command prompt, navigate to the x64 subfolder and run
devnodeclean.exe /n
You’ll see a list of devices that would removed:
Run it again without /n
to remove the devices.
Run it a third time with /n
to confirm that the devices are gone.
Microsoft KB934234 has more details on what registry entries are created and deleted but recommends using DevNodeClean for Server 2012 (and, presumably, for later versions).
To Enum…
On Error Resume Next
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = “.”
x = 0
Set oReg=GetObject(“winmgmts:{impersonationLevel=impersonate}!\\” & strComputer & “\root\default:StdRegProv”)
strKeyPath = “SYSTEM\ControlSet001\Control\DeviceClasses\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}”
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
For Each subkey In arrSubKeys
If Not InStr(subkey, “##?#STORAGE#VolumeSnapshot#HarddiskVolumeSnapshot”) = 0 Then
x = x +1
End If
Next
WScript.Echo “Count ControlSet001 = ” & x
x = 0
Set oReg=GetObject(“winmgmts:{impersonationLevel=impersonate}!\\” & strComputer & “\root\default:StdRegProv”)
strKeyPath = “SYSTEM\ControlSet002\Control\DeviceClasses\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}”
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
For Each subkey In arrSubKeys
If Not InStr(subkey, “##?#STORAGE#VolumeSnapshot#HarddiskVolumeSnapshot”) = 0 Then
x = x +1
End If
Next
WScript.Echo “Count ControlSet002 = ” & x
1.
devnodeclean.exe /r
2.
On Error Resume Next
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = “.”
Set oReg=GetObject(“winmgmts:{impersonationLevel=impersonate}!\\” & strComputer & “\root\default:StdRegProv”)
strKeyPath = “SYSTEM\ControlSet002\Control\DeviceClasses\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}”
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
For Each subkey In arrSubKeys
If Not InStr(subkey, “##?#STORAGE#VolumeSnapshot#HarddiskVolumeSnapshot”) = 0 Then
WScript.Echo subkey
Deletesubkeys HKEY_LOCAL_MACHINE, strKeyPath & “\” & subkey
End If
Next
Sub DeleteSubkeys(reghive, KeyPath)
Set objReg=GetObject(“winmgmts:{impersonationLevel=impersonate}!\\” & strComputer & “\root\default:StdRegProv”)
objReg.EnumKey reghive, KeyPath, arrrSubkeys
If IsArray(arrrSubkeys) Then
For Each strrSubkey In arrrSubkeys
DeleteSubkeys reghive, KeyPath & “\” & strrSubkey
Next
End If
objReg.DeleteKey reghive, KeyPath
End Sub