Ibra86

MSI_StartComponentCleanup

Jul 19th, 2019
1,360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '// original source: https://forums.mydigitallife.net/threads/77708/
  2. option explicit
  3. const HKLM=&H80000002
  4. const instKey="SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products"
  5. dim reg, shell, product,force
  6. force = false
  7. if WScript.Arguments.count > 0 then
  8.  force = WScript.Arguments.Item(0) = "/f"
  9. end if
  10. set reg = getObject ("Winmgmts:root\default:StdRegProv" )
  11. set shell= WScript.CreateObject ("WSCript.shell")
  12. dim arrProducts
  13. reg.EnumKey HKLM,instKey,arrProducts
  14. for each product in arrProducts
  15.  dim productU,productN,arrPatches, patch
  16.  productU=ReconstructProductCode(product)
  17.  reg.GetStringValue HKLM, instKey & "\" & product & "\InstallProperties", "DisplayName", productN
  18.  'Wscript.Echo productU & "\" & productN
  19. reg.EnumKey HKLM,instKey & "\" & product & "\" & "Patches",arrPatches
  20.  if not IsNull(arrPatches) then
  21.   for each patch in arrPatches
  22.    dim patchU,patchN,sta,cmd,ret,msi3,uninsta
  23.    patchU=ReconstructProductCode(patch)
  24.    reg.GetStringValue HKLM, instKey & "\" & product & "\Patches\" & patch, "DisplayName", patchN
  25.    reg.GetDWORDValue HKLM, instKey & "\" & product & "\Patches\" & patch, "State", sta
  26.    reg.GetDWORDValue HKLM, instKey & "\" & product & "\Patches\" & patch, "MSI3", msi3
  27.    reg.GetDWORDValue HKLM, instKey & "\" & product & "\Patches\" & patch, "Uninstallable", uninsta
  28.    if sta = 2 then
  29.     if msi3 = 1 then
  30.      if uninsta = 1 then
  31.       WScript.Echo "Uninstalling "&productN&" : "&patchN &"…"
  32.       cmd="msiexec /package " & productU &" /uninstall " & patchU & " /passive /qr /norestart"
  33.       WScript.Echo cmd
  34.       ret = shell.Run(cmd,0,true)
  35.       WScript.Echo "finished with code " & ret
  36.      else
  37.       if force then
  38.        reg.SetDWORDValue HKLM, instKey & "\" & product & "\Patches\" & patch, "Uninstallable", 1
  39.        WScript.Echo "Force uninstall "&productN&" : "&patchN &"…"
  40.        cmd="msiexec /package " & productU &" /uninstall " & patchU & " /passive /qr /norestart"
  41.        WScript.Echo cmd
  42.        ret = shell.Run(cmd,0,true)
  43.        WScript.Echo "finished with code " & ret
  44.       else
  45.        WScript.Echo productN&" : "&patchN &" is a permanent patch, run this script with /f to uninstall it"
  46.       end if
  47.      end if
  48.     else
  49.      WScript.Echo "Not uninstalling "&productN&" : "&patchN &" β€” Patch removal is available starting with MSI 3.0"
  50.     end if
  51.    end if
  52.   next
  53.  end if
  54. next
  55.  
  56.  
  57.  
  58. Function ReconstructProductCode(ByVal strMungedCode)
  59.  Dim arrSequence
  60.  Dim strProductCode ,intIndex
  61.  
  62.  Const intArraySize    = 32
  63.  
  64.  strProductCode     = "{"
  65.  arrSequence     = Array(8,7,6,5,4,3,2,1,12,11,10,9,16,15,14,13,18,17,20,19,22,21,24,23,26,25,28,27,30,29,32,31)
  66.  '// Generate the Product Code
  67. For intIndex = 0 to intArraySize - 1
  68.   strProductCode    = strProductCode & Mid(strMungedCode,arrSequence(intIndex),1)
  69.   If intIndex = 7 Or intIndex = 11 Or intIndex = 15 Or intIndex = 19 Then
  70.    strProductCode   = strProductCode & "-"
  71.   End If
  72.  Next
  73.  
  74.  strProductCode     = strProductCode & "}"
  75.  ReconstructProductCode    = strProductCode
  76. End Function
Advertisement
Add Comment
Please, Sign In to add comment