Board index » Visual Studio » Please Help Optimize This Code
|
ChadGuiney
|
Please Help Optimize This Code
Visual Studio146
Hello, I have a script that reads a text file into memory and modifies the IIS metabase for the sites listed in the text file and updates the UNCPath key for those site's virtual directories. I have written this code myself, but I am no programmer. I have a feeling that there is a better way to loop through the metabase than the way I am doing it. It does work currently, but I would rather have the code optimized since I will be using it quite a bit moving forward. Can someone please take a look and see if there is a better way to do this? Dim arrSiteList() Set WshNetwork = CreateObject("WScript.Network") ComputerName = WshNetwork.ComputerName Const ForReading = 1 'make FileSystemObject call Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.OpenTextFile ("c:\temp\sites.txt", ForReading) 'read in the number of lines in the text file j = 0 Do Until objTextFile.AtEndOfStream objTextFile.Readline j = j + 1 Loop 'reset the FileSystemObject call Set objFSO = Nothing Set objTextFile = Nothing 'resize my array to the number of lines in the text file '0 based indexing so there's really 1 less than j ReDim arrSiteList(j-1) 'call a new FileSystemObject Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.OpenTextFile ("c:\temp\sites.txt", ForReading) 'populate newly sized array i = 0 Do Until objTextFile.AtEndOfStream arrSiteList(i) = objTextFile.Readline wscript.echo arrSiteList(i) i = i + 1 Loop Count = 0 Path = "\\Server\Share\" SitePoint = ComputerName & "/W3SVC" Set Parent = GetObject("IIS://" & SitePoint) For Each Child In Parent For Each Child2 In Child For Each Child3 In Child2 strPath = Path & Child3.Name for i = 0 to ubound(arrSiteList) 'if Child3.Name is in the array of Sites then execute the following code if arrSiteList(i) = Child3.Name Then 'Set fso = CreateObject ("Scripting.FileSystemObject") If Not objFSO.FolderExists(Child3.Name) Then objFSO.CreateFolder(Child3.Name) End If Select Case Child3.Name 'just skip over these Case "localstart.asp" Case "Printers" Case "IISHelp" Case "iisadmin" Case "$D" Case "D" Case Else For Each Child4 In Child3 If Child4.Name = "REPORTOUTPUT" Then SitePoint = ComputerName & "/W3SVC/" & Child.Name _ & "/" & Child2.Name _ & "/" & Child3.Name _ & "/" & Child4.Name Count = Count + 1 ModifyUNCPath SitePoint, strPath End If Next End Select End If Next Next Next Next '''''''''''''''''''''''''' ' ' ModifyUNCUsername ' ' Modifies the UNCUsername Key Under the Virtual Directories in the Metabase. ' '''''''''''''''''''''''''' Sub ModifyUNCPath(SitePoint, strPath) ' MsgBox ("SitePoint " & SitePoint) On Error Resume Next Set Site = GetObject("IIS://" & SitePoint) On Error GoTo 0 WScript.Echo Space(Level*2 + 1) & "Changing Site #" & Count & " - " & SitePoint Site.Path = strPath Site.SetInfo End Sub Thanks, Robbie - |
