home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 February / CHIP_2_98.iso / software / pelne / optionp / iis4_07.cab / findweb.vbs < prev    next >
Text File  |  1997-10-25  |  5KB  |  193 lines

  1. '---------------------------------------------------------------------------------------------------
  2. ' This function searches a computer for a specified Web Site, and
  3. ' displays information about the site.
  4. '
  5. ' findweb [--computer|-c COMPUTER]
  6. '         <--website|-w WEBSITE>
  7. '         [--help|-?]
  8. '
  9. 'COMPUTER                Computer on which users exists
  10. 'WEBSITE1,WEBSITE2       Virtual Web Sites on which directories will be created
  11. 'NAME1,PATH1,NAME2,PATH2 Virtual Directories names and paths to create
  12. '
  13. 'Example 1        mkwebdir -c MyComputer -w "Default Web Site","Another Web Site"
  14. '                       -v "Virtual Dir1","c:\inetpub\wwwroot\dir1","Virtual Dir2","c:\inetpub\wwwroot\dir2"
  15. '
  16. '---------------------------------------------------------------------------------------------------
  17.  
  18. ' Force explicit declaration of all variables.
  19. Option Explicit
  20.  
  21. On Error Resume Next
  22.  
  23. Dim oArgs, ArgNum
  24.  
  25. Dim ArgComputer, ArgWebSites, ArgVirtualDirs, ArgDirNames(), ArgDirPaths(), DirIndex
  26. Dim ArgComputers
  27.  
  28. Set oArgs = WScript.Arguments
  29. ArgComputers = Array("LocalHost")
  30. ArgWebSites = "1"
  31. ArgNum = 0
  32. While ArgNum < oArgs.Count
  33.     Select Case LCase(oArgs(ArgNum))
  34.         Case "--computer","-c":
  35.             ArgNum = ArgNum + 1
  36.             If (ArgNum >= oArgs.Count) Then
  37.                 Call DisplayUsage
  38.             End If    
  39.             ArgComputers = Split(oArgs(ArgNum), ",", -1)
  40.         Case "--website","-w":
  41.             ArgNum = ArgNum + 1
  42.             If (ArgNum >= oArgs.Count) Then
  43.                 Call DisplayUsage
  44.             End If    
  45.             ArgWebSites = oArgs(ArgNum)
  46.         Case "--virtualdir","-v":
  47.             ArgNum = ArgNum + 1
  48.             If (ArgNum >= oArgs.Count) Then
  49.                 Call DisplayUsage
  50.             End If    
  51.             ArgVirtualDirs = Split(oArgs(ArgNum), ",", -1)
  52.         Case "--help","-?"
  53.             Call DisplayUsage
  54.         Case Else:
  55.             ArgWebSites = oArgs(ArgNum)
  56.     End Select    
  57.  
  58.     ArgNum = ArgNum + 1
  59. Wend
  60.  
  61. Dim foundSite
  62. Dim compIndex
  63. Dim bindInfo
  64. Dim aBinding, binding
  65.  
  66. for compIndex = 0 to UBound(ArgComputers)
  67.     set foundSite = findWeb(ArgComputers(compIndex), ArgWebSites)
  68.     if isObject(foundSite) then
  69.         Trace "  Web Site Number = "&foundSite.Name
  70.         Trace "  Web Site Description = "&foundSite.ServerComment
  71.         aBinding=foundSite.ServerBindings
  72.         if (IsArray(aBinding)) then
  73.             if aBinding(0) = "" then
  74.                 binding = Null
  75.             else
  76.                 binding = getBinding(aBinding(0))
  77.             end if
  78.         else 
  79.             if aBinding = "" then
  80.                 binding = Null
  81.             else
  82.                 binding = getBinding(aBinding)
  83.             end if
  84.         end if
  85.         if (IsArray(binding)) then
  86.             Trace "    Hostname = "&binding(2)
  87.             Trace "    Port = "&binding(1)
  88.             Trace "    IP Address = "&binding(2)
  89.         end if
  90.     else
  91.         Trace "No matching web found."
  92.     end if
  93. next
  94.  
  95. function getBinding(bindstr)
  96.  
  97.     Dim one, two, ia, ip, hn
  98.     
  99.     one=Instr(bindstr,":")
  100.     two=Instr((one+1),bindstr,":")
  101.     
  102.     ia=Mid(bindstr,1,(one-1))
  103.     ip=Mid(bindstr,(one+1),((two-one)-1))
  104.     hn=Mid(bindstr,(two+1))
  105.     
  106.     getBinding=Array(ia,ip,hn)
  107. end function
  108.  
  109. Function findWeb(computer, webname)
  110.     On Error Resume Next
  111.  
  112.     Dim websvc, site
  113.     dim webinfo
  114.     Dim aBinding, binding
  115.  
  116.     set websvc = GetObject("IIS://"&computer&"/W3svc")
  117.     if (Err <> 0) then
  118.         exit function
  119.     end if
  120.     ' First try to open the webname.
  121.     set site = websvc.GetObject("IIsWebServer", webname)
  122.     if (Err = 0) and (not isNull(site)) then
  123.         if (site.class = "IIsWebServer") then
  124.             ' Here we found a site that is a web server.
  125.             set findWeb = site
  126.             exit function
  127.         end if
  128.     end if
  129.     err.clear
  130.     for each site in websvc
  131.         if site.class = "IIsWebServer" then
  132.             '
  133.             ' First, check to see if the ServerComment
  134.             ' matches
  135.             '
  136.             If site.ServerComment = webname Then
  137.                 set findWeb = site
  138.                 exit function
  139.             End If
  140.             aBinding=site.ServerBindings
  141.             if (IsArray(aBinding)) then
  142.                 if aBinding(0) = "" then
  143.                     binding = Null
  144.                 else
  145.                     binding = getBinding(aBinding(0))
  146.                 end if
  147.             else 
  148.                 if aBinding = "" then
  149.                     binding = Null
  150.                 else
  151.                     binding = getBinding(aBinding)
  152.                 end if
  153.             end if
  154.             if IsArray(binding) then
  155.                 if (binding(2) = webname) or (binding(0) = webname) then
  156.                     set findWeb = site
  157.                     exit function
  158.                 End If
  159.             end if 
  160.         end if
  161.     next
  162. End Function
  163.  
  164. '---------------------------------------------------------------------------------
  165. Sub Display(Msg)
  166.     WScript.Echo Now & ". Error Code: " & Hex(Err) & " - " & Msg
  167. End Sub
  168.  
  169. Sub Trace(Msg)
  170.     WScript.Echo Msg    
  171. End Sub
  172.  
  173. Sub DisplayUsage()
  174.     WScript.Echo " findweb [--computer|-c COMPUTER]"
  175.     WScript.Echo "         [WEBSITE]"
  176.     WScript.Echo "         [--help|-?]"
  177.     WScript.Echo ""
  178.     WScript.Echo "Finds the named web on the specified computer."
  179.     WScript.Echo "Displays the site number, description, host name, port,"
  180.     WScript.Echo "and IP Address"
  181.     WScript.Echo ""
  182.     WScript.Echo "Note, WEBSITE is the Web Site on which the directory will be created."
  183.     WScript.Echo "The name can be specified as one of the following, in the priority specified:"
  184.     WScript.Echo " Server Number (i.e. 1, 2, 10, etc.)"
  185.     WScript.Echo " Server Description (i.e ""My Server"")"
  186.     WScript.Echo " Server Host name (i.e. ""www.domain.com"")"
  187.     WScript.Echo " IP Address (i.e., 127.0.0.1)"
  188.     WScript.Echo ""
  189.     WScript.Echo "Example findweb -c MACHINE www.mycompany.com"
  190.     WScript.Quit
  191. End Sub
  192. '---------------------------------------------------------------------------------
  193.