Category Archives: IIS 6

Technique to change any IIS 6 properties programatically

  1. Create a copy of your IIS Metabase before and after you make a change
  2. Compare the copies with a tool like WinMerge
  3. Evaluate function and purpose of properties using MSDN
  4. Set the properties in your scripts using ADSUtil or one of the scripts I have pasted below
    1. For properties that function more like an array you will have to use techniques like those used in the following scripts to properly set their values

Ancillary tools that you might find useful, MetaBase Explorer

Find Website Id By Website Name.vbs

on error resume next
dim Contains
Set ArgObj = WScript.Arguments
If ArgObj.Count < 1 Then
 Wscript.echo "Please specify the name or part name to look for in the host header field!"
 Wscript.echo ""
 Wscript.echo "Example"
 Wscript.echo "  cscript EnumByHostHeader.vbs ccrowe"
else
 Contains = ucase(ArgObj.Item(0))
 dim websrv, site
 dim Found
 dim webinfo
 Found = false
 WScript.echo "Searching for " & Contains & " in the host headers"
 WScript.echo ""
 WScript.echo "Web Site Instance ID - Server Comment - Host Header"
 set websrv = getobject("IIS://Localhost/W3SVC")

 if (err <> 0) then
 else
 err.Clear
 for each site in websrv
 if (site.classname = "IIsWebServer") then
 bindings = Site.ServerBindings
 For Index = LBound(bindings) To UBound(bindings)
 Values = split(bindings(Index), ":")
 HostHeader = ucase(Values(2))
 if (instr(HostHeader, Contains) > 0) then
 Found = true
 WScript.echo site.Name
'          WScript.echo site.Name & " - " & _
'             site.ServerComment & " - " & _
'             HostHeader
 end if
 next
 end if
 next
 end if
 if (Found = false) then
 WScript.echo "The search term " & Contains & " was not found!"
 end if
end if

Import Relay IP List.vbs

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'         Script to Import a bunch of IP addresses to the ReplayIpList
'         and IPSecurity
'                             (c)vijaysk@microsoft.com
'                             blogs.msdn.com/vijaysk
'
'
' USAGE : cscript ImportRelayList.vbs <PathToRelayIP.txt> <PathToSecurityIP.txt>
' PREREQUISITE : This script needs RelayIp.txt and SecurityIp.txt in the same folder or
' the path parameters must be used on the command line to specify the locations.
' FORMAT for *Ip.txt files: Each line should be IP,MASK ex. 127.0.0.1,255.255.255.255
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Option Explicit
Dim objSMTP,objRelayIpList,objCurrentList,objIP,objFSO,objTextFile,count,newIpList(),inputOption,IPTxtPath
Set objSMTP = GetObject("IIS://localhost/smtpsvc/1")
Set objRelayIpList = objSMTP.Get("RelayIpList")
'objRelayIpList is of type IIsIPSecuritySetting http://msdn.microsoft.com/en-us/library/ms525725.aspx

If Wscript.Arguments.Count <> 0 Then
 IPTxtPath = Wscript.Arguments(0)
ELSE
 IPTxtPath = "ip.txt"
End If

Wscript.Echo "============================================"
Wscript.Echo "CURRENT SETTINGS"
Wscript.Echo "================"
Wscript.Echo " "
Wscript.Echo "Computer(s) that may relay through this virtual server."
Wscript.Echo " "
' GrantByDefault returns 0 when "only the list below" is set (false) and -1 when all except the list below is set(true)
If objRelayIpList.GrantByDefault = true Then
 Wscript.Echo "All except the list below :"
 objCurrentList = objRelayIpList.IPDeny
Else
 Wscript.Echo "Only the list below :"
 objCurrentList = objRelayIpList.IPGrant
End If
count = 0
For Each objIP in objCurrentList
 Wscript.Echo objIP
 count = count + 1
Next
If count = 0 Then
 Wscript.Echo "*NIL*"
End If
Wscript.Echo "============================================"
Wscript.Echo " "
Wscript.Echo "Replacing ReplayIpList with the IP address(es) from the ip.txt file."
Wscript.Echo " "

'Hard coding the script to always use the allow option unattended installation
inputOption = "a"

Do While Not((inputOption = "a") Or (inputOption = "d") Or (inputOption = "x") )
Wscript.Echo "ENTER "
Wscript.Echo "A to add to Allow List (Only the list below)"
Wscript.Echo "D to add to Deny List (All except the list below)"
Wscript.Echo "X Exit without making changes"
Wscript.Echo " "
inputOption = lcase(trim(Wscript.StdIn.ReadLine))
Loop
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(IPTxtPath) Then
 Set objTextFile = objFSO.OpenTextFile(IPTxtPath,1)

 count = 0
 Do Until objTextFile.AtEndOfStream
 Redim Preserve newIpList(count)
 newIpList(count) = objTextFile.Readline
 count = count + 1
 Loop
 objTextFile.Close

 'For each objIP in newIpList
 '    Wscript.Echo objIP
 'Next
 Wscript.Echo " "
 Select Case inputOption
 Case "a"
 objRelayIpList.GrantByDefault = false
 objRelayIpList.IpGrant = newIpList
 Wscript.Echo "SET " & count &" address(es) to Allow List"
 Case "d"
 objRelayIpList.GrantByDefault = true
 objRelayIpList.IpDeny = newIpList
 Wscript.Echo "SET " & count &" address(es) to Deny List"
 Case "x"
 Wscript.Echo "Exiting without making changes"
 Wscript.Echo "============================================"
 Wscript.Quit
 End Select

 objSMTP.Put "RelayIpList",objRelayIpList
 objSMTP.SetInfo
 Wscript.Echo " "

 Wscript.Echo "============================================"
Else
 Wscript.Echo "Please create a file ip.txt that contains the list of IP address(es)"
 Wscript.Echo "FORMAT : Each Line should be IP,MASK "
 Wscript.Echo "EX     : 127.0.0.1,255.255.255.255"
End If
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'         Script to Import a bunch of IP addresses to the ReplayIpList             '
'                                                                                  '
'                             (c)vijaysk@microsoft.com                             '
'                             blogs.msdn.com/vijaysk                               '
'                                                                                  '
'                                                                                  '
'         USAGE : cscript ImportRelayList.vbs                                      '
'         PREREQUISITE : This script needs ip.txt in the same folder.              '
'         Store your IP addresses in ip.txt FORMAT: Each line should be IP,MASK    '
'                                                                                  '
'                                                                                  '
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Import IP Security.vbs

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'         Script to Import a bunch of IP addresses to the ReplayIpList             
'         and IPSecurity                                                           
'                             (c)vijaysk@microsoft.com                             
'                             blogs.msdn.com/vijaysk                               
'                                                                                  
'                                                                                  
' USAGE : cscript ImportRelayList.vbs <PathToRelayIP.txt> <PathToSecurityIP.txt>
' PREREQUISITE : This script needs RelayIp.txt and SecurityIp.txt in the same folder or
' the path parameters must be used on the command line to specify the locations.
' FORMAT for *Ip.txt files: Each line should be IP,MASK ex. 127.0.0.1,255.255.255.255
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Option Explicit
Dim objSMTP,objIpSecurity,objCurrentList,objIP,objFSO,objTextFile,count,newIpList(),inputOption,IPTxtPath
Set objSMTP = GetObject("IIS://localhost/smtpsvc/1")
Set objIpSecurity = objSMTP.Get("IPSecurity")
'objIpSecurity is of type IIsIPSecuritySetting http://msdn.microsoft.com/en-us/library/ms525725.aspx

If Wscript.Arguments.Count <> 0 Then
 IPTxtPath = Wscript.Arguments(0)
ELSE
 IPTxtPath = "ip.txt"
End If

Wscript.Echo "============================================"
Wscript.Echo "CURRENT SETTINGS"
Wscript.Echo "================"
Wscript.Echo " "
Wscript.Echo "Computer(s) that may connect to this virtual server."
Wscript.Echo " "
' GrantByDefault returns 0 when "only the list below" is set (false) and -1 when all except the list below is set(true)
If objIpSecurity.GrantByDefault = true Then
 Wscript.Echo "All except the list below :"
 objCurrentList = objIpSecurity.IPDeny
Else
 Wscript.Echo "Only the list below :"
 objCurrentList = objIpSecurity.IPGrant
End If
count = 0
For Each objIP in objCurrentList
 Wscript.Echo objIP
 count = count + 1
Next
If count = 0 Then
 Wscript.Echo "*NIL*"
End If
Wscript.Echo "============================================"
Wscript.Echo " "
Wscript.Echo "Replacing IPSecurity with the IP address(es) from the " & IPTxtPath & " file."
Wscript.Echo " "

'Hard coding the script to always use the allow option unattended installation
inputOption = "a"

Do While Not((inputOption = "a") Or (inputOption = "d") Or (inputOption = "x") )
Wscript.Echo "ENTER "
Wscript.Echo "A to add to Allow List (Only the list below)"
Wscript.Echo "D to add to Deny List (All except the list below)"
Wscript.Echo "X Exit without making changes"
Wscript.Echo " "
inputOption = lcase(trim(Wscript.StdIn.ReadLine))
Loop
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(IPTxtPath) Then
 Set objTextFile = objFSO.OpenTextFile(IPTxtPath,1)

 count = 0
 Do Until objTextFile.AtEndOfStream
 Redim Preserve newIpList(count)
 newIpList(count) = objTextFile.Readline
 count = count + 1
 Loop
 objTextFile.Close

 'For each objIP in newIpList
 '    Wscript.Echo objIP
 'Next
 Wscript.Echo " "
 Select Case inputOption
 Case "a"
 objIpSecurity.GrantByDefault = false
 objIpSecurity.IpGrant = newIpList
 Wscript.Echo "SET " & count &" address(es) to Allow List"        
 Case "d"
 objIpSecurity.GrantByDefault = true
 objIpSecurity.IpDeny = newIpList
 Wscript.Echo "SET " & count &" address(es) to Deny List"
 Case "x"
 Wscript.Echo "Exiting without making changes"
 Wscript.Echo "============================================"
 Wscript.Quit
 End Select

 objSMTP.Put "IPSecurity",objIpSecurity
 objSMTP.SetInfo
 Wscript.Echo " "

 Wscript.Echo "============================================"
Else
 Wscript.Echo "Please create a file ip.txt that contains the list of IP address(es)"
 Wscript.Echo "FORMAT : Each Line should be IP,MASK "
 Wscript.Echo "EX     : 127.0.0.1,255.255.255.255"
End If
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'         Script to Import a bunch of IP addresses to the ReplayIpList             '
'                                                                                  '
'                             (c)vijaysk@microsoft.com                             '
'                             blogs.msdn.com/vijaysk                               '
'                                                                                  '
'                                                                                  '
'         USAGE : cscript ImportRelayList.vbs                                      '
'         PREREQUISITE : This script needs ip.txt in the same folder.              '
'         Store your IP addresses in ip.txt FORMAT: Each line should be IP,MASK    '
'                                                                                  '
'                                                                                  '
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Advertisements