web-developer
HomeWindows/IISDHTMLRankingIndex ServerContact me 
 


 

How can I set the application protection for a web site?
The following script allows you to set the application protection for a particular web site.
You must provide the web site ID which you can obtain by running the FindWeb.VBS script in the following folder.
You also must specify LOW, MEDIUM or HIGH as the protection level.
Medium is only available on IIS5
Example: cscript SetSiteApplicationProtection.vbs medium 1 Site Description Application Protection

=======================================================================

 Site 1 - Default Web Site Medium (Pooled) Code Sample

Option Explicit

' Chris Crowe
' www.iisfaq.com
' 1 - January 2001
'
' For lots more ADSI scripts come and visit www.iisfaq.com

Dim Website, AppProtection, IISOBJ, Site, Description, IIS4

function IsAppIsolatedABoolean
    Dim IIsSchemaPath, IIsSchemaObject

    ' Get the Schema of the property and determine if it's multivalued
    IIsSchemaPath = "IIS://localhost/Schema/AppIsolated"
    Set IIsSchemaObject = GetObject(IIsSchemaPath)
'   Wscript.Echo "Schema = " & UCase(IIsSchemaObject.Syntax)
    IsAppIsolatedABoolean = (UCase(IIsSchemaObject.Syntax) = "BOOLEAN")
    Set IIsSchemaObject = nothing
end function

Sub DisplayUsage
    WScript.Echo "usage: cscript SetSiteApplicationProtection.vbs"
    WScript.Echo "                WebSiteID"
    WScript.Echo "                LOW | MEDIUM  | HIGH"
    WScript.Echo "                [--help|-?]"
    WScript.Echo ""
    WScript.Echo "Example 1: SetSiteApplicationProtection.vbs 1 low"
    WScript.Echo "  This will set the web site with id of 1 to low protection level."
    WScript.Echo ""
    WScript.Echo "Example 2: SetSiteApplicationProtection.vbs 1 high"
    WScript.Echo "  This will set the web site with id of 1 to high protection level."
    WScript.Echo ""
    WScript.Echo "NOTE: MEDIUM is only supported on IIS5"
    WScript.Echo "      To find the web site # use findweb.vbs"
    WScript.Echo ""
    WScript.Echo "Please come to www.iisfaq.com for more ADSI scripts for IIS"
    WScript.Quit(1)
End Sub

Sub CheckCommandLine()
Dim OArgs, ArgNum

Set oArgs = WScript.Arguments
ArgNum = 0
AppProtection = -1
WebSite = -1
While ArgNum < oArgs.Count

    Select Case LCase(oArgs(ArgNum))
        Case "low":
            AppProtection = 1
        Case "medium":
            if (IIS4 = true) then
                Call DisplayUsage
            end if
            AppProtection = 2
        Case "high":
            AppProtection = 3
        Case "--help","-?":
            Call DisplayUsage
        Case Else:
            WebSite = clng(oArgs(ArgNum))
    End Select  

    ArgNum = ArgNum + 1
Wend
if (AppProtection = -1) or (WebSite = -1) then
   Call DisplayUsage
end if
end sub


' This function will return the site details or "" if it does not meed the application protection requirements
function ReturnSiteProtectionIIS5(Site)
Dim Protection, SiteRoot

ReturnSiteProtectionIIS5 = ""
Set SiteRoot = getObject("IIS://Localhost/W3svc/" & Site.Name & "/Root")
if (Siteroot.AppIsolated = 1) then
    Protection = "High (Isolated)"
elseif (Siteroot.AppIsolated = 2) then
    Protection = "Medium (Pooled)"
else
    Protection = "Low (IIS Process)"
end if
ReturnSiteProtectionIIS5 = "Site " & Site.Name & " - " & Site.ServerComment & space(40-len(site.servercomment)) & Protection
Set SiteRoot = nothing
end function

' This function will return the site details or "" if it does not meed the application protection requirements
function ReturnSiteProtectionIIS4(Site)
Dim Protection, SiteRoot

ReturnSiteProtectionIIS4 = ""
Set SiteRoot = getObject("IIS://Localhost/W3svc/" & Site.Name & "/Root")
if (Siteroot.AppIsolated = true) then
    Protection = "High (Isolated)"
else    
    Protection = "Low (IIS Process)"
end if

ReturnSiteProtectionIIS4 = "Site " & Site.Name & " - " & Site.ServerComment & space(40-len(site.servercomment)) & Protection
Set SiteRoot = nothing
end function

Function SetSiteProtectionLevel()
    Set Site = getObject("IIS://Localhost/W3svc/"   & WebSite & "/root")
    if (IIS4 = true) then
        if (AppProtection = 1) then ' low
            Site.AppIsolated = false
        else ' high
            Site.AppIsolated = true
        end if
    else     
        if (AppProtection = 1) then ' low
            Site.AppIsolated = 0
        elseif (AppProtection = 2) then ' medium
            Site.AppIsolated = 2
        else    ' high
            Site.AppIsolated = 1
        end if
    end if
    site.SetInfo
'   WScript.echo ""
end function

' Initialize some variables to determine what to show
IIS4 = IsAppIsolatedABoolean()

Call CheckCommandLine()
' Display a heading
WScript.Echo "Site   Description " & space(28) & "Application Protection"
WScript.Echo "======================================================================="

' Read the W3SVC object
Set IISOBJ = getObject("IIS://Localhost/W3svc/" & WebSite)
Call SetSiteProtectionLevel()
' Read the W3SVC object
if (IIS4 = true) then
    WScript.Echo ReturnSiteProtectionIIS4(IISOBJ)
else
    WScript.Echo ReturnSiteProtectionIIS5(IISOBJ)
end if
Set IISOBJ = nothing