' Parse file and make modifications to the server bindings Dim Filename, Line, FSO, textFile, WebSiteInstanceID, Bits, RestOfLine Const ValidateOnly = true Const Process = false ' Check to see if we have a valid binding entry - it must have 2 ":" in it Function isValidBinding(X) Dim Colons, pos Colons = 0 for pos = 1 to len(X) if (Mid(X, Pos,1) = ":") then Colons = Colons+1 end if next isValidBinding = (Colons = 2) end function ' Is this a valid number? Function isNumber(X) Dim digit on error resume next err.clear Digit = cint(X) IsNumber = (err = 0) end function function Work(Validate) Work = false const ForReading = 1 Filename = "IPAddressFile.Txt" Set FSO = CreateObject("Scripting.FileSystemObject") if (Fso.FileExists(Filename) = false) then WScript.echo "File does not exist: " & Filename exit function end if Set textfile = FSO.OpenTextFile(Filename, ForReading) LineNumber = 0 while Textfile.AtEndOfStream = false LineNumber = LineNumber+1 Line = trim(textFile.ReadLine) if (line = "") or (left(line, 1) = ";") then ' Just a comment ignore it else ' We now must parse the line returned ' Split the line at | Bits = Split(line, "|") WebSiteInstanceID = Bits(0) if (isNumber(WebSiteInstanceID) = false) then WScript.Echo "WebSiteInstanceID is not valid: " & WebSiteInstanceID & " - Line " & LineNumber WScript.Quit exit function end if RestOfLine = trim(Bits(1)) AllBindingsComments = Split(RestOfLine, ";") AllBindings = trim(AllBindingsComments(0)) if (UBound(AllBindingsComments) > 0) then Comments = trim(AllBindingsComments(1)) else comments = "" end if Bindings = Split(trim(AllBindings), "*") if (Validate = true) then for each binding in Bindings if (IsValidBinding(Binding) = false) then WScript.Echo "WebSiteInstanceID " & WebSiteInstanceID & " - Invalid Binding : " & _ Binding & " - Line " & LineNumber WScript.Quit exit function end if next on error resume next Set IISOBJ = GetObject("IIS://Localhost/W3SVC/" & WebSiteInstanceID) if (Err <> 0) then WScript.Echo "WebSiteInstanceID " & WebSiteInstanceID & _ " - Can not connect to the web site! - Error 0x" & hex(err) & " - " & Err.Description WScript.Quit exit function end if set IISOBJ = nothing else Set IISOBJ = GetObject("IIS://Localhost/W3SVC/" & WebSiteInstanceID) on error resume next IISOBJ.ServerBindings = Bindings Err.Clear IISOBJ.SetInfo if (Err <> 0) then WScript.Echo "WebSiteInstanceID " & WebSiteInstanceID & _ " - Error while saving chnages - Error 0x" & hex(err) & " - " & Err.Description WScript.Quit exit function end if WScript.Echo "Processed : WebSiteInstance = " & WebSiteInstanceID & " - " & IISOBJ.ServerComment Set IISOBJ = Nothing end if end if wend set textfile =nothing Set FSO = nothing Work = true End Function if (Work(ValidateOnly) = true) then Work(Process) end if