Microsoft KB Archive/302988

= How to programmatically add or remove an ISAPI filter in IIS by using ADSI =

Article ID: 302988

Article Last Modified on 11/21/2006

-

APPLIES TO


 * Microsoft Internet Information Services 5.1
 * Microsoft Internet Information Services 5.0
 * Microsoft Internet Information Server 4.0

-



This article was previously published under Q302988



We strongly recommend that all users upgrade to Microsoft Internet Information Services (IIS) version 6.0 running on Microsoft Windows Server 2003. IIS 6.0 significantly increases Web infrastructure security. For more information about IIS security-related topics, visit the following Microsoft Web site:

http://www.microsoft.com/technet/security/prodtech/IIS.mspx



SUMMARY
Global and site-level Internet Server Application Programming Interface (ISAPI) filter information is stored in the Internet Information Server (IIS) metabase or the Internet Information Services (IIS) metabase. You can access the metabase programmatically through the IIS Admin Objects (IISAO), which uses Active Directory Service Interfaces (ADSI), or through the IIS Admin Base Object (IISABO), which uses Microsoft Visual C++ interfaces. This article describes how to add and remove ISAPI filters in IIS by using ADSI.

Note The sample code in this article must be run with the security context of a member of the local Administrators group on the IIS server.

Remove an ISAPI filter by using ADSI
The following sample code removes a global filter named &quot;myFilter&quot; from the ISAPI filters list on the master properties of the WWW Publishing service. Dim objFilterProps, objFilters Dim strLoadOrder Dim strFilterName Dim intStartFilt

strFilterName = &quot;myFilter&quot;

Set objFilters = GetObject(&quot;IIS://LocalHost/W3SVC/Filters&quot;) strLoadOrder = objFilters.FilterLoadOrder If strLoadOrder <> &quot;&quot; Then If Right(strLoadOrder, 1) <> &quot;,&quot; Then strLoadOrder = strLoadOrder & &quot;,&quot; End If      intStartFilt = InStr(strLoadOrder, strFilterName) strLoadOrder = Mid(strLoadOrder, 1, intStartFilt - 1) & _ Mid(strLoadOrder, intStartFilt + Len(strFilterName) + 1, _            Len(strLoadOrder)) objFilters.FilterLoadOrder= strLoadOrder objFilters.SetInfo objFilters.Delete &quot;IIsFilter&quot;, strFilterName End If   Set objFilters = Nothing Note that to remove the ISAPI filter from memory, you must restart IISADMIN service.

Troubleshooting
The example that is provided in this article demonstrates how to add and remove global ISAPI filters. To add or remove site-level ISAPI filters, use GetObject(&quot;IIS://LocalHost/W3SVC/1/Filters&quot;) to reference the correct metabase node, instead of the GetObject(&quot;IIS://LocalHost/W3SVC/Filters&quot;) example that is used in this article. The &quot;1&quot; in &quot;/W3SVC/1/&quot; refers to the metabase site instance ID of the particular Web site (in this case, the default Web site).

