Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '// original source: https://forums.mydigitallife.net/threads/77708/
- option explicit
- const HKLM=&H80000002
- const instKey="SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products"
- dim reg, shell, product,force
- force = false
- if WScript.Arguments.count > 0 then
- force = WScript.Arguments.Item(0) = "/f"
- end if
- set reg = getObject ("Winmgmts:root\default:StdRegProv" )
- set shell= WScript.CreateObject ("WSCript.shell")
- dim arrProducts
- reg.EnumKey HKLM,instKey,arrProducts
- for each product in arrProducts
- dim productU,productN,arrPatches, patch
- productU=ReconstructProductCode(product)
- reg.GetStringValue HKLM, instKey & "\" & product & "\InstallProperties", "DisplayName", productN
- 'Wscript.Echo productU & "\" & productN
- reg.EnumKey HKLM,instKey & "\" & product & "\" & "Patches",arrPatches
- if not IsNull(arrPatches) then
- for each patch in arrPatches
- dim patchU,patchN,sta,cmd,ret,msi3,uninsta
- patchU=ReconstructProductCode(patch)
- reg.GetStringValue HKLM, instKey & "\" & product & "\Patches\" & patch, "DisplayName", patchN
- reg.GetDWORDValue HKLM, instKey & "\" & product & "\Patches\" & patch, "State", sta
- reg.GetDWORDValue HKLM, instKey & "\" & product & "\Patches\" & patch, "MSI3", msi3
- reg.GetDWORDValue HKLM, instKey & "\" & product & "\Patches\" & patch, "Uninstallable", uninsta
- if sta = 2 then
- if msi3 = 1 then
- if uninsta = 1 then
- WScript.Echo "Uninstalling "&productN&" : "&patchN &"β¦"
- cmd="msiexec /package " & productU &" /uninstall " & patchU & " /passive /qr /norestart"
- WScript.Echo cmd
- ret = shell.Run(cmd,0,true)
- WScript.Echo "finished with code " & ret
- else
- if force then
- reg.SetDWORDValue HKLM, instKey & "\" & product & "\Patches\" & patch, "Uninstallable", 1
- WScript.Echo "Force uninstall "&productN&" : "&patchN &"β¦"
- cmd="msiexec /package " & productU &" /uninstall " & patchU & " /passive /qr /norestart"
- WScript.Echo cmd
- ret = shell.Run(cmd,0,true)
- WScript.Echo "finished with code " & ret
- else
- WScript.Echo productN&" : "&patchN &" is a permanent patch, run this script with /f to uninstall it"
- end if
- end if
- else
- WScript.Echo "Not uninstalling "&productN&" : "&patchN &" β Patch removal is available starting with MSI 3.0"
- end if
- end if
- next
- end if
- next
- Function ReconstructProductCode(ByVal strMungedCode)
- Dim arrSequence
- Dim strProductCode ,intIndex
- Const intArraySize = 32
- strProductCode = "{"
- 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)
- '// Generate the Product Code
- For intIndex = 0 to intArraySize - 1
- strProductCode = strProductCode & Mid(strMungedCode,arrSequence(intIndex),1)
- If intIndex = 7 Or intIndex = 11 Or intIndex = 15 Or intIndex = 19 Then
- strProductCode = strProductCode & "-"
- End If
- Next
- strProductCode = strProductCode & "}"
- ReconstructProductCode = strProductCode
- End Function
Advertisement
Add Comment
Please, Sign In to add comment