RegistryCleanup.vbs.in 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. On Error goto 0
  2. Const HKEY_LOCAL_MACHINE = &H80000002
  3. Const HKEY_CURRENT_USER = &H80000001
  4. Const strObjRegistry = "winmgmts:\\.\root\default:StdRegProv"
  5. Function RegistryDeleteKeyRecursive(regRoot, strKeyPath)
  6. Set objRegistry = GetObject(strObjRegistry)
  7. objRegistry.EnumKey regRoot, strKeyPath, arrSubkeys
  8. If IsArray(arrSubkeys) Then
  9. For Each strSubkey In arrSubkeys
  10. RegistryDeleteKeyRecursive regRoot, strKeyPath & "\" & strSubkey
  11. Next
  12. End If
  13. objRegistry.DeleteKey regRoot, strKeyPath
  14. End Function
  15. Function RegistryListSubkeys(regRoot, strKeyPath)
  16. Set objRegistry = GetObject(strObjRegistry)
  17. objRegistry.EnumKey regRoot, strKeyPath, arrSubkeys
  18. RegistryListSubkeys = arrSubkeys
  19. End Function
  20. Function GetUserSID()
  21. Dim objWshNetwork, objUserAccount
  22. Set objWshNetwork = CreateObject("WScript.Network")
  23. Set objUserAccount = GetObject("winmgmts://" & objWshNetwork.UserDomain & "/root/cimv2").Get("Win32_UserAccount.Domain='" & objWshNetwork.ComputerName & "',Name='" & objWshNetwork.UserName & "'")
  24. GetUserSID = objUserAccount.SID
  25. End Function
  26. Function RegistryCleanupSyncRootManager()
  27. strSyncRootManagerKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\SyncRootManager"
  28. arrSubKeys = RegistryListSubkeys(HKEY_LOCAL_MACHINE, strSyncRootManagerKeyPath)
  29. If IsArray(arrSubkeys) Then
  30. arrSubkeys=Filter(arrSubkeys, Session.Property("APPNAME"))
  31. End If
  32. If IsArray(arrSubkeys) Then
  33. arrSubkeys=Filter(arrSubkeys, GetUserSID())
  34. End If
  35. If IsArray(arrSubkeys) Then
  36. For Each strSubkey In arrSubkeys
  37. RegistryDeleteKeyRecursive HKEY_LOCAL_MACHINE, strSyncRootManagerKeyPath & "\" & strSubkey
  38. Next
  39. End If
  40. End Function
  41. Function RegistryCleanupCfApiShellExtensions()
  42. Set objRegistry = GetObject(strObjRegistry)
  43. strShellExtAppId = "Software\Classes\AppID\@CFAPI_SHELLEXT_APPID_REG@"
  44. strShellExtThumbnailHandlerClsId = "Software\Classes\CLSID\@CFAPI_SHELLEXT_THUMBNAIL_HANDLER_CLASS_ID_REG@"
  45. strShellExtCustomStateHandlerClsId = "Software\Classes\CLSID\@CFAPI_SHELLEXT_CUSTOM_STATE_HANDLER_CLASS_ID_REG@"
  46. rootKey = HKEY_CURRENT_USER
  47. If objRegistry.EnumKey(rootKey, strShellExtAppId, arrSubKeys) = 0 Then
  48. RegistryDeleteKeyRecursive rootKey, strShellExtAppId
  49. End If
  50. If objRegistry.EnumKey(rootKey, strShellExtThumbnailHandlerClsId, arrSubKeys) = 0 Then
  51. RegistryDeleteKeyRecursive rootKey, strShellExtThumbnailHandlerClsId
  52. End If
  53. If objRegistry.EnumKey(rootKey, strShellExtCustomStateHandlerClsId, arrSubKeys) = 0 Then
  54. RegistryDeleteKeyRecursive rootKey, strShellExtCustomStateHandlerClsId
  55. End If
  56. End Function
  57. Function RegistryCleanup()
  58. RegistryCleanupSyncRootManager()
  59. RegistryCleanupCfApiShellExtensions()
  60. End Function