1 'In order to get the list of versions to uninstall during deferred mode,
2 'We need to set UninstallOldShibVersions property during the Immediate
3 'Execution sequence. We can then read the value via CustomActionData.
4 'To accomplish this, create a CA as follows:
5 ' Action: SetShibVersionsImmediate
6 ' Source: UninstallOldShibVersions
8 ' Target: [OLDSHIBVERSIONSFOUND]
9 'Sequence this action near the beginning of InstallExecuteSequence with
10 ' Condition: (NOT Installed) AND (OLDSHIBVERSIONSFOUND <> "") AND (OLDSHIBPERFORMUNINSTALL = "TRUE")
13 '*********************************
14 '* This code is the entire body of shib_uninstall_isapi_filter.vbs
15 '* The only exception is that the main function of that code is made
16 '* a Sub in this code so we can call it, and we pass it the InstallDir
17 '* from the Uninst.isu string instead of pulling it from the MSI.
18 '*********************************
20 Sub DeleteISAPIFilters(IISPath,dllPath)
22 Dim filter, FiltersObj, LoadOrder, FilterArray, FilterItem
24 Set FiltersObj = GetObject(IISPath & "/Filters")
25 LoadOrder = FiltersObj.FilterLoadOrder
27 for each filter in FiltersObj
28 if (filter.Class = "IIsFilter") then
29 if (filter.FilterPath = dllPath) then
31 'Delete the found filter here
32 'If there's anything to potentially delete...
33 if (LoadOrder <> "") then
34 FilterArray = split(LoadOrder,",")
36 for each FilterItem in FilterArray
37 if (FilterItem <> filter.Name) then
38 LoadOrder = LoadOrder & FilterItem & ","
41 'Remove trailing comma if any filters were kept
42 if (LoadOrder <> "") then
43 LoadOrder = mid(LoadOrder,1,len(LoadOrder)-1)
46 'Set the Load Order to the new shibboleth-less order
47 if (FiltersObj.FilterLoadOrder <> LoadOrder) then
48 FiltersObj.FilterLoadOrder = LoadOrder
53 'Delete the actual IISFilter object
54 FiltersObj.Delete "IIsFilter",filter.Name
63 Sub DeleteFileExtensions(siteObj, dllPath)
65 Dim ScriptMaps, newScriptMaps
66 Dim line, lineArray, lineIndex
70 ScriptMaps = siteObj.ScriptMaps
71 redim newScriptMaps(0)
73 'copy each entry from the old ScriptMaps to newScriptMaps
74 'unless it is for dllPath
75 for each line in ScriptMaps
76 lineArray = split(line,",")
77 if (lineArray(1) <> dllPath) then
78 redim preserve newScriptMaps(lineIndex)
79 newScriptMaps(lineIndex) = line
80 lineIndex = lineIndex + 1
85 'If we found dllPath, then use the newScriptMaps instead
86 if (existsFlag = "exists") then
87 siteObj.ScriptMaps = newScriptMaps
94 Sub CleanUpISAPI(InstallDir)
99 Dim site, siteObj, sitePath
102 'Don't show errors, we'll handle anything important
105 'Attempt to get W3SVC. If failure, end script (e.g. IIS isn't available)
106 Set WebObj = GetObject("IIS://LocalHost/W3SVC")
109 'Get the INSTALLDIR value via CustomActionData
110 'Commented out for embedding in this .vbs, passed instead
111 ' InstallDir = Session.Property("CustomActionData")
113 'Remove all trailing backslashes to normalize
114 do while (mid(InstallDir,Len(InstallDir),1) = "\")
115 InstallDir = mid(InstallDir,1,Len(InstallDir)-1)
118 ShibISAPIPath = InstallDir & "\libexec\isapi_shib.dll"
121 'First do the master service
122 DeleteISAPIFilters "IIS://LocalHost/W3SVC",ShibISAPIPath
124 for each site in WebObj
125 if (site.Class = "IIsWebServer") then
126 sitePath = "IIS://LocalHost/W3SVC/" & site.Name
127 DeleteISAPIFilters sitePath,ShibISAPIPath
131 'Delete File Extensions
132 'First do the master service
133 DeleteFileExtensions WebObj,ShibISAPIPath
135 for each site in WebObj
136 if (site.Class = "IIsWebServer") then
137 set siteObj = GetObject("IIS://LocalHost/W3SVC/" & site.Name & "/ROOT")
138 DeleteFileExtensions siteObj,ShibISAPIPath
143 'Delete Web Services Extension (universal, no need to do for each site)
144 WebObj.DeleteExtensionFileRecord ShibISAPIPath
152 '******** Begin Main Code ***************
154 Dim WshShell, WshEnv, versionArray, versionElement, versionNumbers, regValue, UninstallArray, uninstallStr, UninstIsuArray, path, pathArray, NewPathEnv
157 Set WshShell = CreateObject("WScript.Shell")
159 versionNumbers = Session.Property("CustomActionData")
161 versionArray = split( versionNumbers, vbCRLF )
163 for each versionElement in versionArray
164 if (versionElement<>"") then
166 'if RegRead fails, it won't set regValue, and it will hold the last value instead. Make sure the 'last' value is ""
169 regValue=WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & versionElement & "\UninstallString")
170 if (regValue<>"") then
171 UninstallArray = split( regValue, " -f")
172 'Save off the INSTALLDIR path for later use
173 UninstIsuArray = split(UninstallArray(1),"Uninst.isu")
174 InstallDir = UninstIsuArray(0)
176 'Now create the silent uninstall string and execute it
177 uninstallStr=UninstallArray(0) & " -y -a -f" & UninstallArray(1)
178 WshShell.Run( uninstallStr )
180 'Remove entry from path environment variable
181 Set WshEnv = WshShell.Environment("SYSTEM")
182 PathEnv = WshEnv("PATH")
184 PathArray = split(PathEnv,";")
185 for each path in PathArray
186 if ((path<>InstallDir & "lib\") AND (path<>InstallDir & "lib")) then
187 NewPathEnv = NewPathEnv & path & ";"
190 NewPathEnv = mid(NewPathEnv,1,len(NewPathEnv)-1)
191 WshEnv("PATH") = NewPathEnv
193 'Clean up all the ISAPI filters and file extension
194 CleanUpISAPI InstallDir