''''''''''''''''''''''''''''''''''''
'
' ADSUTIL.VBS
'
' Date:   7/24/97
' Revision History:
'     Date         Comment
'    7/24/97       Initial version started
'    5/8/98        Bug fixes and ENUM_ALL
'    12/1/98       Fixed display error on list data.
'    7/27/99       AppCreate2 fix
'    8/5/99        Dont display encrypted data
''''''''''''''''''''''''''''''''''''
Option Explicit
On Error Resume Next

''''''''''''''''''
' Main Script Code
''''''''''''''''''
Dim ArgObj ' Object which contains the command line argument
Dim Result ' Result of the command function call
Dim Args(999) ' Array that contains all of the non-global arguments
Dim ArgCount ' Tracks the size of the Args array

' Used for string formatting
Dim Spacer
Dim SpacerSize

Const IIS_DATA_NO_INHERIT = 0
Const IIS_DATA_INHERIT = 1
Const GENERAL_FAILURE = 2
Const GENERAL_WARNING = 1
Const AppCreate_InProc = 0
Const AppCreate_OutOfProc = 1
Const AppCreate_PooledOutOfProc = 2

Const APPSTATUS_NOTDEFINED = 2
Const APPSTATUS_RUNNING = 1
Const APPSTATUS_STOPPED = 0

Spacer = "                                " ' Used to format the strings
SpacerSize = Len(Spacer)

' Note: The default execution mode may be under WScript.exe.
' That would be very annoying since WScript has popups for Echo.
' So, I want to detect that, and warn the user that it may cause
' problems.


' Get the Arguments object
Set ArgObj = WScript.Arguments

' Test to make sure there is at least one command line arg - the command
'*****************************************************
Dim TargetServer 'The server to be examined/modified

If Len(TargetServer) = 0 Then
    TargetServer = "localhost"
End If
'*****************************************************

'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
'
'                          SSA_Section
'
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'#######################
'SSA values
Dim IIS_Properties
Dim StringInArray
Dim Paths
Dim PathToWWWRoot
Dim fso, f
Dim ScriptFullPath, ScriptFolderPath
PathToWWWRootExist = false
'ini variables
Dim IniOptionsNameArray
Dim OptionNameToGet
Dim OptionValue
Dim INI
Dim WshShell
Dim ThreadsCount

IniOptionsNameArray = Array("Count")
OptionNameToGet=""
OptionValue = ""
ThreadsCount = ""
'#######################

'%%%%%%%%%%%%%%%%%%%%%%
'ObjectsCreation   
Set fso = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")
Set INI = CreateObject("GetIniFunctions.WSC")
'%%%%%%%%%%%%%%%%%%%%%%   

''''''''''''''''''''
' SSA_Section Main
'''''''''''''''''''

ScriptFullPath = WScript.ScriptFullName
Set f = fso.GetFile(ScriptFullPath)
ScriptFolderPath = f.ParentFolder

'Get wwwroot path
ArgCount = 1
CommenceOperation("ENUM_ALL")

Paths = Split(IIS_Properties, "#", -1, 1)

For Each StringInArray In Paths
 If Instr(1, Ucase(StringInArray) , "WWWROOT") Then
 PathToWWWRoot = StringInArray 
 PathToWWWRootExist = true 
 Exit For
 End If
Next

'copy html and java applet
If PathToWWWRootExist = true Then
 If (fso.FolderExists(ScriptFolderPath&"\Video")) Then
  fso.CreateFolder(PathToWWWRoot&"\Video")
  fso.CopyFolder ScriptFolderPath&"\Video\*", PathToWWWRoot&"\Video\", true
  fso.CopyFile ScriptFolderPath&"\Video\*.*", PathToWWWRoot&"\Video\",true
 Else 
  WScript.Echo "Can not find folder: Video. Can not copy files."
 End If 

'Apply settings
 ArgCount = 3
 Args(1) = "/W3SVC/1/ROOT/AccessExecute"
 Args(2) = "Истина"
 CommenceOperation("SET")
 Args(1) = "/W3SVC/1/ROOT/AccessScript"
 CommenceOperation("SET")
 Args(1) = "/W3SVC/1/ROOT/AppIsolated"
 Args(2) = "1"
 CommenceOperation("SET")
 'get settings from ini
 For Each OptionNameToGet in  IniOptionsNameArray
  OptionValue = INI.GetIniSectionOptionValue("[ThreadsCount]", OptionNameToGet, ScriptFolderPath) 
  If OptionValue <> "OptionFalse" Then
   Select Case OptionNameToGet
    Case "Count"
	
    If IsNumeric(OptionValue) = True Then
     ThreadsCount = OptionValue
    End If 
   End Select
  Else 
   WScript.Echo "Can't get in Initialize.ini file in [ThreadsCount] section "&OptionNameToGet&" option. Using default." 
  End If
 Next 
 'Writing settings to registry
WshShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Services\InetInfo\Parameters\MaxPoolThreads", ThreadsCount, "REG_DWORD"
Else 
 WScript.Echo "Path to wwwroot not exist. Quit" 
End If 
''''''''''''''''''''''''
' End of SSA_Section Main
''''''''''''''''''''''''




' Call the function associated with the given command
Function CommenceOperation(strCommand)
 Select Case UCase(strCommand)
    Case "SET"
        Result = SetCommand()
    Case "CREATE"
        Result = CreateCommand("")
    Case "DELETE"
        Result = DeleteCommand()
    Case "GET"
        Result = GetCommand()
    Case "ENUM"
        Result = EnumCommand(False, "")
    Case "ENUM_ALL"
        Result = EnumCommand(True, "")
		'WScript.Echo "MY___FUNCTIONWERTWERTEWR---------WERTWERTWER"&IIS_Properties
    Case "ENUMALL"
        Result = EnumCommand(True, "")
    Case "COPY"
        Result = CopyMoveCommand(True)   ' The TRUE means COPY, not MOVE
    Case "MOVE"
        Result = CopyMoveCommand(False)   ' The FALSE means MOVE, not COPY
    Case "CREATE_VDIR"
        Result = CreateCommand("IIsWebVirtualDir")
    Case "CREATE_VSERV"
        Result = CreateCommand("IIsWebServer")
    Case "START_SERVER"
        Result = StartServerCommand()
    Case "STOP_SERVER"
        Result = StopServerCommand()
    Case "PAUSE_SERVER"
        Result = PauseServerCommand()
    Case "CONTINUE_SERVER"
        Result = ContinueServerCommand()
' New Stuff being added
    Case "FIND"
        Result = FindData()
    Case "COPY"
        WScript.Echo "COPY is not yet supported.  It will be soon."
    Case "APPCREATEINPROC"
        Result = AppCreateCommand(AppCreate_InProc)
    Case "APPCREATEOUTPROC"
        Result = AppCreateCommand(AppCreate_OutOfProc)
    Case "APPCREATEPOOLPROC"
        Result = AppCreateCommand(AppCreate_PooledOutOfProc)
    Case "APPDELETE"
        Result = AppDeleteCommand()
    Case "APPUNLOAD"
        Result = AppUnloadCommand()
    Case "APPDISABLE"
        Result = AppDisableCommand()
    Case "APPENABLE"
        Result = AppEnableCommand()
    Case "APPGETSTATUS"
        Result = AppGetStatusCommand()
    Case "HELP"
        DisplayHelpMessageEx

' End New Stuff

    Case Else
        WScript.Echo "Command not recognized: " & Args(0)
        WScript.Echo "For help, just type ""Cscript.exe adsutil.vbs""."
        Result = GENERAL_FAILURE

 End Select
End Function 



WScript.Quit (Result)

''''''''''
' End Main
''''''''''

''''''''''''''''''''''''''
'
' EnumCommand Function
'
' Enumerates all properties at a path in the metabase.
'
''''''''''''''''''''''''''
Function EnumCommand(Recurse, StartPath)

    On Error Resume Next

    Dim IIsObject
    Dim IIsObjectPath
    Dim IIsSchemaObject
    Dim IIsSchemaPath
    Dim ObjectPath
    Dim MachineName
    Dim ValueIndex
    Dim ValueList
    Dim ValueListArray
    Dim ValueString
    Dim PropertyName
    Dim PropertyAttribObj
    Dim PropertyListSet
    Dim PropertyList
    Dim PropertyObjPath
    Dim PropertyObject
    Dim ChildObject
    Dim ChildObjectName
    Dim EnumPathsOnly
    Dim EnumAllData
    Dim ErrMask
    Dim IsInherit

    Dim PropertyDataType

    Dim SpecialResult

    Dim PathOnlyOption
    PathOnlyOption = "/P"
    EnumCommand = 0 ' Assume Success
    EnumPathsOnly = False ' Assume that the user wants all of the data items
    EnumAllData = False ' Assume that the user wants only the actual data items

    If (ArgCount = 1) Then
        ObjectPath = ""
        EnumPathsOnly = False
        ArgCount = 2
    ElseIf (ArgCount = 2) Then
        If UCase(Args(1)) = PathOnlyOption Then
            ObjectPath = ""
            EnumPathsOnly = True
        Else
            ObjectPath = Args(1)
            EnumPathsOnly = False
        End If
    ElseIf (ArgCount = 3) Then

        If UCase(Args(1)) = PathOnlyOption Then
            ObjectPath = Args(2)
            EnumPathsOnly = True
        ElseIf UCase(Args(2)) = PathOnlyOption Then
            ObjectPath = Args(1)
            EnumPathsOnly = True
        Else
            WScript.Echo "Error: Invalid arguments for the ENUM command"
            WScript.Quit (GENERAL_FAILURE)
        End If
    Else
        WScript.Echo "Error: Wrong number of Args for the ENUM command"
        WScript.Quit (GENERAL_FAILURE)
    End If

    If StartPath <> "" Then ObjectPath = StartPath

    SanitizePath ObjectPath
    MachineName = SeparateMachineName(ObjectPath)

    IIsObjectPath = "IIS://" & MachineName
    If (ObjectPath <> "") Then
        IIsObjectPath = IIsObjectPath & "/" & ObjectPath
    End If

    Set IIsObject = GetObject(IIsObjectPath)

    If (Err.Number <> 0) Then
        WScript.Echo
        ReportError ()
        WScript.Echo "Error Trying To ENUM the Object (GetObject Failed): " & ObjectPath
        WScript.Quit (Err.Number)
    End If

    ' Get the Schema of the object and enumerate through all of the properties
    IIsSchemaPath = IIsObject.Schema
    Set IIsSchemaObject = GetObject(IIsSchemaPath)

    If (Err.Number <> 0) Then
        WScript.Echo
        ReportError ()
        WScript.Echo "Error Trying To GET the Schema of the class: " & IIsSchemaPath
        WScript.Quit (Err.Number)
    End If

    ReDim PropertyListSet(1)
    PropertyListSet(0) = IIsSchemaObject.MandatoryProperties
    PropertyListSet(1) = IIsSchemaObject.OptionalProperties

    If (Err.Number <> 0) Then
        WScript.Echo
        ReportError ()
        WScript.Echo "Error trying to get the list of properties: " & IIsSchemaPath
        WScript.Quit (Err.Number)
    End If

     ' This now checks for an empty OptionalProperties list
    If TypeName (PropertyListSet(1)) <> "Variant()" Then
        WScript.Echo
        WScript.Echo "Warning: The optionalproperties list is of an invalid type"
        WScript.Echo
    ElseIf (UBound (PropertyListSet(1)) = -1) Then
        WScript.Echo
        WScript.Echo "Warning: The OptionalProperties list for this node is empty."
        WScript.Echo
    End If

    If (Not EnumPathsOnly) Then
        For Each PropertyList In PropertyListSet

            For Each PropertyName In PropertyList
                If Err <> 0 Then
                    Exit For
                End If

                ' Test to see if the property is even set at this node
                IsInherit = False
                Err.Clear
                Set PropertyAttribObj = IIsObject.GetPropertyAttribObj(PropertyName)
                If (Err.Number = 0) Then

                    If (PropertyAttribObj.IsInherit) Then
                        IsInherit = True
                    End If
                    Err.Clear

                    If (IsInherit = False) Or (EnumAllData) Then
                    ' If the above statement is true, then the data exists here or the user wants it anyway.

                        PropertyObjPath = "IIS://" & MachineName & "/Schema/" & PropertyName
                        Set PropertyObject = GetObject(PropertyObjPath)

                        If (Err.Number <> 0) Then
                            WScript.Echo
                            ReportError ()
                            WScript.Echo "Error trying to enumerate the Optional properties (Couldn't Get Property Information): " & PropertyObjPath
                            WScript.Echo "Last Property Name: " & PropertyName
                            WScript.Echo "PropertyObjPath: " & PropertyObjPath
                            'WScript.Quit (Err.Number)
                            WScript.Echo
                            EnumCommand = Err.Number
                            Err.Clear
                        End If

                        ValueList = ""
                        ValueListArray = ""

                        PropertyDataType = UCase(PropertyObject.Syntax)
                        Select Case PropertyDataType
                        Case "STRING"
                            ValueList = IIsObject.Get(PropertyName)
                            If (IsSecureProperty(PropertyName,MachineName) <> True) AND PropertyName = "Path" Then

    						  IIS_Properties = IIS_Properties + ValueList + "#"
'							  IIS_Properties = IIS_Properties + vbCrLf +  ValueList 

                            End If


                        End Select

                    End If ' End if data exists at the current node

                Else ' Error during GetPropertyAttribObj
                    Err.Clear 'ignore and go to the next property
                End If

                If (Err.Number <> 0) Then
                    WScript.Echo
                    ReportError ()
                    WScript.Echo "Error trying to enumerate the Optional properties (Error trying to get property value): " & PropertyObjPath
                    WScript.Echo "Last Property Name: " & PropertyName
                    WScript.Echo "PropertyObjPath: " & PropertyObjPath
                    ' If there is an ADS error, just ignore it and move on
                    ' otherwise, quit
                    If ((Err.Number) >= &H80005000) And ((Err.Number) < &H80006000) Then
                        Err.Clear
                        WScript.Echo "Continuing..."
                    Else
                        WScript.Quit (Err.Number)
                    End If
                    WScript.Echo
                End If
            Next
        Next

        If (Err.Number <> 0) Then
            WScript.Echo "Error trying to enumerate the properties lists:"
            ReportError ()
            WScript.Echo
            EnumCommand = Err.Number
            Err.Clear
        End If

    End If ' End if (Not EnumPathsOnly)

    'WScript.Echo "Last Error: " & Err & " (" & Hex (Err) & "): " & Err.Description
    ' Now, enumerate the data paths
    For Each ChildObject In IIsObject
        If (Err.Number <> 0) Then Exit For

        ChildObjectName = Right(ChildObject.AdsPath, Len(ChildObject.AdsPath) - 6)
        ChildObjectName = Right(ChildObjectName, Len(ChildObjectName) - InStr(ChildObjectName, "/") + 1)
        If (Recurse = True) And (ChildObjectName <> Args(1)) Then
            EnumCommand = EnumCommand(True, ChildObjectName)
        End If
    Next

    If (Err.Number <> 0) Then
        WScript.Echo "Error trying to enumerate the child nodes"
        ReportError ()
        WScript.Echo
        EnumCommand = Err.Number
        Err.Clear
    End If



End Function



''''''''''''''''''''''''''''''
'
' Function SeparateMachineName
'
' This function will get the machine name from the Path parameter
' that was passed into the script.  It will also alter the passed in
' path so that it contains only the rest of the path - not the machine
' name.  If there is no machine name in the path, then the script
' will assume LocalHost.
'
''''''''''''''''''''''''''''''
Function SeparateMachineName(Path)
    On Error Resume Next

    ' Temporarily, just return LocalHost
    ' SeparateMachineName = "LocalHost"

    SeparateMachineName = TargetServer

    Exit Function
End Function



Sub ReportError()
'   On Error Resume Next

    Dim ErrorDescription

    Select Case (Err.Number)
        Case &H80070003
            ErrorDescription = "The path requested could not be found."
        Case &H80070005
            ErrorDescription = "Access is denied for the requested path or property."
        Case &H80070094
            ErrorDescription = "The requested path is being used by another application."
        Case Else
            ErrorDescription = Err.Description
    End Select

    WScript.Echo ErrorDescription
    WScript.Echo "ErrNumber: " & Err.Number & " (0x" & Hex(Err.Number) & ")"
End Sub









Sub SanitizePath(ObjectPath)
    On Error Resume Next

    ' Remove WhiteSpace
    Do While (Left(ObjectPath, 1) = " ")
        ObjectPath = Right(ObjectPath, Len(ObjectPath) - 1)
    Loop

    Do While (Right(ObjectPath, 1) = " ")
        ObjectPath = Left(ObjectPath, Len(ObjectPath) - 1)
    Loop

    ' Replace all occurrences of \ with /
    ObjectPath = Replace(ObjectPath, "\", "/")

    ' Remove leading and trailing slashes
    If Left(ObjectPath, 1) = "/" Then
        ObjectPath = Right(ObjectPath, Len(ObjectPath) - 1)
    End If

    If Right(ObjectPath, 1) = "/" Then
        ObjectPath = Left(ObjectPath, Len(ObjectPath) - 1)
    End If

    If (Err.Number <> 0) Then
        ReportError ()
        WScript.Echo "Error Trying To Sanitize the path: " & ObjectPath
        WScript.Quit (Err.Number)
    End If

End Sub

 ''''''''''''''''''''''''''
'
' IsSecureProperty
'
' Checks to see if the property requires special processing in order to
' display its contents.
'
''''''''''''''''''''''''''
Function IsSecureProperty(ObjectParameter,MachineName)

    On Error Resume Next
    Dim PropObj,Attribute
    Set PropObj = GetObject("IIS://" & MachineName & "/schema/" & ObjectParameter)
    If (Err.Number <> 0) Then
        ReportError ()
        WScript.Echo "Error trying to get the property: " & err.number
        WScript.Quit (Err.Number)
    End If
    Attribute = PropObj.Secure
    If (Attribute = True) Then
        IsSecureProperty = True
    Else
        IsSecureProperty = False
    End If
End Function

''''''''''''''''''''''''''
'
' SetCommand Function
'
' Sets the value of a property in the metabase.
'
''''''''''''''''''''''''''
Function SetCommand()
    Dim IIsObject
    Dim IIsObjectPath
    Dim IIsSchemaObject
    Dim IIsSchemaPath
    Dim ObjectPath
    Dim ObjectParameter
    Dim MachineName
    Dim ValueIndex
    Dim ValueList
    Dim ValueDisplay
    Dim ValueDisplayLen
    Dim ValueDataType

    Dim ValueData

    Dim ObjectDataType

    On Error Resume Next

    SetCommand = 0 ' Assume Success

    If ArgCount < 3 Then
        WScript.Echo "Error: Wrong number of Args for the SET command"
        WScript.Quit (GENERAL_FAILURE)
    End If

    ObjectPath = Args(1)
    SanitizePath ObjectPath
    MachineName = SeparateMachineName(ObjectPath)
    ObjectParameter = SplitParam(ObjectPath)

    ' Some Property Types have special needs - like ServerCommand.
    ' Check to see if this is a special command.  If it is, then process it special.
    If (IsSpecialSetProperty(ObjectParameter)) Then
        SetCommand = DoSpecialSetProp(ObjectPath, ObjectParameter, MachineName)
        Exit Function
    End If

    If ObjectPath = "" Then
        IIsObjectPath = "IIS://" & MachineName
    Else
        IIsObjectPath = "IIS://" & MachineName & "/" & ObjectPath
    End If
    Set IIsObject = GetObject(IIsObjectPath)

    If (Err.Number <> 0) Then
        ReportError ()
        WScript.Echo "Error Trying To Get the Object: " & ObjectPath
        WScript.Quit (Err.Number)
    End If

    ' Get the Schema of the property and determine if it's multivalued
    IIsSchemaPath = "IIS://" & MachineName & "/Schema/" & ObjectParameter
    Set IIsSchemaObject = GetObject(IIsSchemaPath)

    If (Err.Number <> 0) Then
        ReportError ()
        WScript.Echo "Error Trying To GET the Schema of the property: " & IIsSchemaPath
        WScript.Quit (Err.Number)
    End If

    ObjectDataType = UCase(IIsSchemaObject.Syntax)
    SanitizePath ObjectDataType

    Select Case (ObjectDataType)

    Case "STRING"
        ValueList = Args(2)
        IIsObject.Put ObjectParameter, (ValueList)

    Case "EXPANDSZ"
        ValueList = Args(2)
        IIsObject.Put ObjectParameter, (ValueList)

    Case "INTEGER"
        ' Added to convert hex values to integers
		
        ValueData = Args(2)

        If (UCase(Left(ValueData, 2))) = "0X" Then
                ValueData = "&h" & Right(ValueData, Len(ValueData) - 2)
        End If

        ValueList = StringTo32BitUnsignedInteger(ValueData)
        IIsObject.Put ObjectParameter, (ValueList)

    Case "BOOLEAN"
        ValueList = CBool(Args(2))
        IIsObject.Put ObjectParameter, (ValueList)

    Case "LIST"
        ReDim ValueList(ArgCount - 3)
        For ValueIndex = 2 To ArgCount - 1
                ValueList(ValueIndex - 2) = Args(ValueIndex)
        Next

        IIsObject.Put ObjectParameter, (ValueList)

    Case Else
        WScript.Echo "Error: Unknown data type in schema: " & IIsSchemaObject.Syntax

    End Select

    IIsObject.Setinfo

    If (Err.Number <> 0) Then
        ReportError ()
        WScript.Echo "Error Trying To SET the Property: " & ObjectParameter
        WScript.Quit (Err.Number)
    End If

    ' The function call succeeded, so display the output
    ' Set up the initial part of the display - the property name and data type
    ValueDisplay = ObjectParameter
    ValueDisplayLen = Len(ValueDisplay)

    If (ValueDisplayLen < SpacerSize) Then
        ValueDisplay = ValueDisplay & (Right(Spacer, SpacerSize - ValueDisplayLen)) & ": " & "(" & ObjectDataType & ") "
Else
        ValueDisplay = ValueDisplay & ": " & "(" & TypeName(ValueList) & ") "
    End If

    ' Create the rest of the display - The actual data
    If (IIsSchemaObject.MultiValued) Then
        For ValueIndex = 0 To UBound(ValueList)
            ValueDisplay = ValueDisplay & """" & ValueList(ValueIndex) & """ "
        Next
    Else
        If (UCase(IIsSchemaObject.Syntax) = "STRING") Then
            If (IsSecureProperty(ObjectParameter,MachineName) = True) Then
                ValueDisplay = ValueDisplay & """" & "**********" & """"
            Else
                ValueDisplay = ValueDisplay & """" & ValueList & """"
            End If
        ElseIf (UCase(IIsSchemaObject.Syntax) = "INTEGER") Then
            ValueDisplay = ValueDisplay & UnsignedIntegerToString(ValueList)
        Else
            ValueDisplay = ValueDisplay & ValueList
        End If
    End If

    ' Display the output
    WScript.Echo ValueDisplay

    SetCommand = 0 ' Success

End Function

''''''''''''''''''''''''''
'
' IsSpecialSetProperty
'
' Checks to see if the property is a type that needs to be handled
' specially for compatibility with mdutil
'
''''''''''''''''''''''''''
Function IsSpecialSetProperty(ObjectParameter)

    On Error Resume Next

    Select Case UCase(ObjectParameter)
        Case "APPPOOLCOMMAND"
            IsSpecialSetProperty = True
        Case "SERVERCOMMAND"
            IsSpecialSetProperty = True
        Case "ACCESSPERM"
            IsSpecialSetProperty = True
        Case "VRPATH"
            IsSpecialSetProperty = True
        Case "AUTHORIZATION"
            IsSpecialSetProperty = True
        Case "MIMEMAP"
            IsSpecialSetProperty = True
        Case Else
            IsSpecialSetProperty = False
    End Select
End Function

''''''''''''''''''''''''''
'
' DoSpecialSetProp
'
' Handles datatypes that need to be handled
' specially for compatibility with mdutil
'
''''''''''''''''''''''''''
Function DoSpecialSetProp(ObjectPath, ObjectParameter, MachineName)
    Dim IIsObjectPath
    Dim IIsObject
    Dim ValueList
    Dim ValueDisplay
    Dim PermIndex

    On Error Resume Next

    DoSpecialSetProp = 0 ' Assume Success
    Select Case UCase(ObjectParameter)
        Case "SERVERCOMMAND"

            IIsObjectPath = "IIS://" & MachineName & "/" & ObjectPath
            Set IIsObject = GetObject(IIsObjectPath)

            If (Err.Number <> 0) Then
                ReportError ()
                WScript.Echo "Error Trying To Get the Object: " & ObjectPath
                WScript.Quit (Err.Number)
            End If

            If (IIsObject.KeyType <> "IIsWebServer") Then
                ReportError ()
                WScript.Echo "Can't set ServerCommand on a non-IIsWebServer object."
                WScript.Quit (GENERAL_FAILURE)
            End If

            ValueList = CLng(Args(2))
            Select Case ValueList
                Case 1
                    IIsObject.Start
                    If (Err.Number <> 0) Then
                        ReportError ()
                        WScript.Echo "Error Trying To Start the server: " & ObjectPath
                        WScript.Quit (Err.Number)
                    End If
                    WScript.Echo "Server " & ObjectPath & " Successfully STARTED"
                Case 2
                    IIsObject.Stop
                    If (Err.Number <> 0) Then
                        ReportError ()
                        WScript.Echo "Error Trying To Stop the server: " & ObjectPath
                        WScript.Quit (Err.Number)
                    End If
                    WScript.Echo "Server " & ObjectPath & " Successfully STOPPED"
                Case 3
                    IIsObject.Pause
                    If (Err.Number <> 0) Then
                        ReportError ()
                        WScript.Echo "Error Trying To Pause the server: " & ObjectPath
                        WScript.Quit (Err.Number)
                    End If
                    WScript.Echo "Server " & ObjectPath & " Successfully PAUSED"
                Case 4
                    IIsObject.Continue
                    If (Err.Number <> 0) Then
                        ReportError ()
                        WScript.Echo "Error Trying To Continue the server: " & ObjectPath
                        WScript.Quit (Err.Number)
                    End If
                    WScript.Echo "Server " & ObjectPath & " Successfully Continued"
                Case Else
                    WScript.Echo "Invalid ServerCommand: " & ValueList
                    DoSpecialSetProp = GENERAL_FAILURE
            End Select
            Exit Function

        Case "APPPOOLCOMMAND"

            IIsObjectPath = "IIS://" & MachineName & "/" & ObjectPath
            Set IIsObject = GetObject(IIsObjectPath)

            If (Err.Number <> 0) Then
                ReportError ()
                WScript.Echo "Error Trying To Get the Object: " & ObjectPath
                WScript.Quit (Err.Number)
            End If

            If (IIsObject.KeyType <> "IIsApplicationPool") Then
                ReportError ()
                WScript.Echo "Can't set AppPoolCommand on a non-IIsApplicationPool object."
                WScript.Quit (GENERAL_FAILURE)
            End If

            ValueList = CLng(Args(2))
            Select Case ValueList
                Case 1
                    IIsObject.Start
                    If (Err.Number <> 0) Then
                            ReportError ()
                            WScript.Echo "Error Trying To Start the application pool: " & ObjectPath
                            WScript.Quit (Err.Number)
                    End If
                    WScript.Echo "Application pool " & ObjectPath & " Successfully STARTED"
                Case 2
                    IIsObject.Stop
                    If (Err.Number <> 0) Then
                            ReportError ()
                            WScript.Echo "Error Trying To Stop the application pool: " & ObjectPath
                            WScript.Quit (Err.Number)
                    End If
                    WScript.Echo "Application pool " & ObjectPath & " Successfully STOPPED"
                Case Else
                    WScript.Echo "Invalid AppPoolCommand: " & ValueList
                    DoSpecialSetProp = GENERAL_FAILURE
            End Select
            Exit Function

        Case "ACCESSPERM"
            IIsObjectPath = "IIS://" & MachineName & "/" & ObjectPath
            Set IIsObject = GetObject(IIsObjectPath)

            If (Err.Number <> 0) Then
                ReportError ()
                WScript.Echo "Error Trying To Get the Object: " & ObjectPath
                WScript.Quit (Err.Number)
            End If

            ' Set the access flags to None, first, and then add them back, as necessary
            IIsObject.AccessFlags = 0

            ' Set up the display output
            ValueDisplay = "AccessFlags (AccessPerm)" & (Right(Spacer, SpacerSize - Len("AccessFlags (AccessPerm)")) & ": " & "(" & TypeName(IIsObject.AccessFlags) & ") ")

            ' Attempt to convert parameter to number
            Dim APValue
            Dim TempValStr

            TempValStr = Args(2)

            ' Check for Hex
            If (UCase(Left(Args(2), 2)) = "0X") Then
                TempValStr = "&H" & Right(TempValStr, Len(TempValStr) - 2)
            End If

            APValue = CLng(TempValStr)

            If (Err.Number = 0) Then
                IIsObject.AccessFlags = APValue
                ValueDisplay = ValueDisplay & " " & APValue & " (0x" & Hex(APValue) & ")"
            Else
                Err.Clear
                For PermIndex = 2 To ArgCount - 1
                    Select Case UCase(Args(PermIndex))
                        Case "READ"
                            IIsObject.AccessRead = True
                            ValueDisplay = ValueDisplay & " Read"
                        Case "WRITE"
                            IIsObject.AccessWrite = True
                            ValueDisplay = ValueDisplay & " Write"
                        Case "EXECUTE"
                            IIsObject.AccessExecute = True
                            ValueDisplay = ValueDisplay & " Execute"
                        Case "SCRIPT"
                            IIsObject.AccessScript = True
                            ValueDisplay = ValueDisplay & " Script"
                        Case Else
                            WScript.Echo "Error: Setting not supported: " & Args(PermIndex)
                            WScript.Quit (GENERAL_FAILURE)
                    End Select
                Next
            End If

            If (Err.Number <> 0) Then
                ReportError ()
                WScript.Echo "Error Trying To Set data on the Object: " & ObjectPath
                WScript.Quit (Err.Number)
            End If

            IIsObject.Setinfo

            If (Err.Number <> 0) Then
                ReportError ()
                WScript.Echo "Error Trying To Set data on the Object: " & ObjectPath
                WScript.Quit (Err.Number)
            End If

            ' Send the current settings to the screen
            WScript.Echo ValueDisplay

        Case "VRPATH"
            IIsObjectPath = "IIS://" & MachineName & "/" & ObjectPath
            Set IIsObject = GetObject(IIsObjectPath)

            If (Err.Number <> 0) Then
                ReportError ()
                WScript.Echo "Error Trying To Get the Object: " & ObjectPath
                WScript.Quit (Err.Number)
            End If

            ' Set the access flags to None, first, and then add them back, as necessary
            IIsObject.Path = Args(2)

            If (Err.Number <> 0) Then
                ReportError ()
                WScript.Echo "Error Trying To Set data on the Object: " & ObjectPath
                WScript.Quit (Err.Number)
            End If

            ' Set up the display output
            ValueDisplay = "Path (VRPath)" & (Right(Spacer, SpacerSize - Len("Path (VRPath)")) & ": " & "(" & TypeName(IIsObject.Path) & ") " & IIsObject.Path)

            IIsObject.Setinfo

            If (Err.Number <> 0) Then
                ReportError ()
                WScript.Echo "Error Trying To Set data on the Object: " & ObjectPath
                WScript.Quit (Err.Number)
            End If

            ' Send the current settings to the screen
            WScript.Echo ValueDisplay

        Case "AUTHORIZATION"
            IIsObjectPath = "IIS://" & MachineName & "/" & ObjectPath
            Set IIsObject = GetObject(IIsObjectPath)

            If (Err.Number <> 0) Then
                ReportError ()
                WScript.Echo "Error Trying To Get the Object: " & ObjectPath
                WScript.Quit (Err.Number)
            End If

            ' Set the auth flags to None, first, and then add them back, as necessary
            IIsObject.AuthFlags = 0

            ' Set up the display output
            ValueDisplay = "Authorization" & (Right(Spacer, SpacerSize - Len("Authorization")) & ": " & "(" & TypeName(IIsObject.AuthFlags) & ") ")

            For PermIndex = 2 To ArgCount - 1
                Select Case UCase(Args(PermIndex))
                    Case "NT"
                        IIsObject.AuthNTLM = True
                        ValueDisplay = ValueDisplay & " NT"
                    Case "ANONYMOUS"
                        IIsObject.AuthAnonymous = True
                        ValueDisplay = ValueDisplay & " Anonymous"
                    Case "BASIC"
                        IIsObject.AuthBasic = True
                        ValueDisplay = ValueDisplay & " Basic"
                    Case Else
                        WScript.Echo "Error: Setting not supported: " & Args(PermIndex)
                        WScript.Quit (GENERAL_FAILURE)
                End Select
            Next

            If (Err.Number <> 0) Then
                ReportError ()
                WScript.Echo "Error Trying To Set data on the Object: " & ObjectPath
                WScript.Quit (Err.Number)
            End If

            IIsObject.Setinfo

            If (Err.Number <> 0) Then
                ReportError ()
                WScript.Echo "Error Trying To Set data on the Object: " & ObjectPath
                WScript.Quit (Err.Number)
            End If

            ' Send the current settings to the screen
            WScript.Echo ValueDisplay

        Case "MIMEMAP"
            DoSpecialSetProp = MimeMapSet(ObjectPath, ObjectParameter, MachineName)
'       Case "FILTER"
'           DoSpecialSetProp = FiltersSet()
        Case Else

            DoSpecialSetProp = GENERAL_FAILURE
    End Select
End Function

Function SplitParam(ObjectPath)
' Note: Assume the string has been sanitized (no leading or trailing slashes)
    On Error Resume Next

    Dim SlashIndex
    Dim TempParam
    Dim ObjectPathLen

    SplitParam = ""  ' Assume no parameter
    ObjectPathLen = Len(ObjectPath)

    ' Separate the path of the node from the parameter
    SlashIndex = InStrRev(ObjectPath, "/")

    If (SlashIndex = 0) Or (SlashIndex = ObjectPathLen) Then
        TempParam = ObjectPath
        ObjectPath = "" ' ObjectParameter is more important
    Else
        TempParam = ObjectPath
        ObjectPath = Left(ObjectPath, SlashIndex - 1)
        TempParam = Right(TempParam, Len(TempParam) - SlashIndex)
    End If

    SplitParam = TempParam

    If (Err.Number <> 0) Then
        ReportError ()
        WScript.Echo "Error trying to Split the parameter from the object: " & ObjectPath
        WScript.Quit (Err.Number)
    End If

End Function

' We want to be able to cope with 32-bit unsigned integers,
' but CLng works with 32-bit signed integers
Function StringTo32BitUnsignedInteger(ValueData)
    Dim numVal
    If (UCase(Left(ValueData, 2))) = "0X" Then
        ValueData = "&h" & Right(ValueData, Len(ValueData) - 2)
    End If

    numVal = Int(ValueData) ' Despite its name, this actually turns it into a double.

    If numVal < 0 Or numVal >= 4294967296 Then
        ' this number is out of the range of a 32-bit unsigned integer,
        Err.Raise 6 ' overflow
    ElseIf numVal >= 2147483648 Then
        ' bias downwards by -2^32
        numVal = numVal - 4294967296
    End If

    StringTo32BitUnsignedInteger = CLng(numVal)
End Function