using Colin.Bowern;

Life ends with a semi-colon.

  Home  |   Contact  |   Syndication    |   Login
  22 Posts | 0 Stories | 2 Comments | 33 Trackbacks

News

Archives

Post Categories

Looking to deploy the Atlas Framework to our production environment and I realized their registration script for the http handler only registers the script on the first site (site ID 1).  Since we have multiple sites I thought I'd through together a more robust registration script based on my previous blog entry that I thought I'd share:

    1 Option Explicit

    2 Dim WMIService, ApplicationPool, ApplicationPools, Applications, index, VirtualDirectorySettings

    3 Dim ApplicationName, ScriptMap, FoundMapping, ScriptMapCollection, LastPosition

    4 Const ComputerName = "localhost"

    5 Const ScriptMapExtension = ".asbx"

    6 Const ScriptMapEntry = ".asbx,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST"

    7 

    8 Set WMIService = GetObject("winmgmts:{authenticationLevel=pktPrivacy}\\" + ComputerName + "\root\microsoftiisv2")

    9 Set ApplicationPools = WMIService.ExecQuery("Select * From IIsApplicationPool Where Name LIKE 'W3SVC/AppPools/%'")

   10 

   11 For Each ApplicationPool in ApplicationPools

   12     WScript.Echo "Inspecting Application Pool " + ApplicationPool.Name

   13     ApplicationPool.EnumAppsInPool Applications

   14     For index = 0 to UBound(Applications)

   15         ApplicationName = CleanApplicationName(Applications(index))

   16         Set VirtualDirectorySettings = GetObject( "IIS://" + ComputerName + "/" + ApplicationName)

   17         If Err.number = 0 Then

   18             ScriptMapCollection = VirtualDirectorySettings.ScriptMaps

   19             FoundMapping = False

   20             For Each ScriptMap in ScriptMapCollection

   21                 If LCase(Left(ScriptMap, Len(ScriptMapExtension))) = ScriptMapExtension then

   22                     WScript.Echo ApplicationName + " - Updating (Previous: " + ScriptMap + ")"

   23                     ScriptMap = ScriptMapEntry

   24                     FoundMapping = True

   25                     Exit For

   26                 End IF

   27             Next

   28 

   29             If FoundMapping = False Then

   30                 LastPosition = UBound(ScriptMapCollection) + 1

   31                 Redim Preserve ScriptMapCollection(LastPosition)

   32                 WScript.Echo ApplicationName + " - Adding " + ScriptMapExtension

   33                 ScriptMapCollection(LastPosition) = ScriptMapEntry

   34             End If

   35 

   36             VirtualDirectorySettings.ScriptMaps = ScriptMapCollection

   37             VirtualDirectorySettings.SetInfo

   38         Else

   39             WScript.Echo ApplicationName & " - Unable to locate application virtual directory."

   40         End If

   41     Next

   42     WScript.Echo

   43 Next

   44 

   45 ' Trims the leading /LM/ and trailing /

   46 Function CleanApplicationName(applicationName)

   47     Dim ReturnValue

   48 

   49     If Len(applicationName) < 5 Then

   50         WScript.Echo "applicationName should be greater than 5 characters: " + applicationName

   51         Exit Function

   52     End If

   53 

   54     ReturnValue = Mid(applicationName, 5)

   55     ReturnValue = Mid(ReturnValue, 1, Len(ReturnValue) - 1)

   56 

   57     CleanApplicationName = ReturnValue

   58 End Function

posted on Thursday, May 11, 2006 9:19 AM