You can add an ISAPI filter programmatically by using the IIS Admin Objects. Filters can be added to either the WWW service or to an individual Web site. To add a filter you must first create an IIsFilters object. IIsFilters is a container object that you can populate with IIsFilter objects.
For example, the following script would add an IIsFilters object to the WWW service. Note that a Filters object is created for the WWW service when IIS is installed. For an individual Web site you may need to create this object before you can use it.
Dim FiltersObj
Dim LoadOrder
Set FiltersObj = GetObject("IIS://LocalHost/W3SVC/Filters")
LoadOrder = FiltersObj.FilterLoadOrder
If LoadOrder <> "" Then
LoadOrder = LoadOrder & ","
End If
LoadOrder = LoadOrder & "myFilter"
FiltersObj.FilterLoadOrder = LoadOrder
FiltersObj.SetInfo
Once you have gained access to the parent IIsFilters container object, you can create a new IIsFilter object and set its properties. The following script adds a new IIsFilter, myFilter
, and sets the path and description.
Dim FilterObj
Dim FilterName
FilterName = "myFilter"
FilterPath = "C:\iisfilts\myfilter.dll"
FilterDesc = "This is my filter"
Set FilterObj = FiltersObj.Create("IIsFilter", FilterName)
FilterObj.FilterPath = FilterPath
FilterObj.FilterDescription = FilterDesc
FilterObj.SetInfo
For more information on the Admin Objects see Using IIS Admin Objects.