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

  1. '------------------------------------------------------------------------------------------------
  2. '
  3. ' Print the tree of administration objects starting either at the specified node or the root 
  4. ' node of the local machine.
  5. '
  6. ' Usage: disptree [--ADSPath|-a ROOT NODE] 
  7. '                       [--NoRecurse|-n] 
  8. '                       [--help|-?]
  9. '
  10. ' ROOT NODE      Optional argument specifies the ADSI path of the first node of the tree
  11. ' No Recurse     Specifying this keeps the script from recursing through the tree
  12. '
  13. ' Example 1: disptree
  14. ' Example 2: disptree -a IIS://LocalHost/w3svc --NoRecurse
  15. '------------------------------------------------------------------------------------------------
  16.  
  17. ' Force declaration of variables.
  18. Option Explicit
  19.  
  20. On Error Resume Next
  21.  
  22. Dim oFirstNode, Recurse, CurrentObj, RootNodePath
  23.  
  24. ' By default, we recurse.
  25. Recurse = True
  26.  
  27. ' Set the default path
  28. RootNodePath = "IIS://LocalHost"
  29.  
  30. Dim oArgs, ArgNum
  31. Set oArgs = WScript.Arguments
  32. ArgNum = 0
  33. While ArgNum < oArgs.Count
  34.  
  35.     Select Case LCase(oArgs(ArgNum))
  36.         Case "--adspath","-a":
  37.             ArgNum = ArgNum + 1
  38.             RootNodePath = oArgs(ArgNum)
  39.         Case "--norecurse","-n":
  40.             Recurse = false
  41.         Case "--help","-?":
  42.             Call DisplayUsage    
  43.         Case Else:
  44.             Call DisplayUsage
  45.     End Select    
  46.  
  47.     ArgNum = ArgNum + 1
  48. Wend
  49.  
  50. Set oFirstNode = GetObject(RootNodePath)
  51.  
  52. If Err <> 0 Then
  53.     Display "Couldn't get the first node!"
  54.     WScript.Quit (1)
  55. End If
  56.  
  57. ' Begin displaying tree
  58. Call DisplayTree(oFirstNode, 0)
  59.  
  60. ' This is the sub that will do the actual recursion
  61. Sub DisplayTree(FirstObj, Level)
  62.     If (FirstObj.Class = "IIsWebServer") Or (FirstObj.Class = "IIsFtpServer") Then
  63.         WScript.Echo Space(Level*2) & FirstObj.Name & " - " & FirstObj.ServerComment & " (" & FirstObj.Class & ")"    
  64.     Else
  65.         WScript.Echo Space(Level*2) & FirstObj.Name & " (" & FirstObj.Class & ")"    
  66.     End If
  67.  
  68.     ' Only recurse if so specified.
  69.     If (Level = 0) or (Recurse) then
  70.         For Each CurrentObj in FirstObj
  71.             Call DisplayTree(CurrentObj, Level + 1)
  72.         Next
  73.     End If
  74. End Sub 
  75.  
  76. ' Display the usage for this script
  77. Sub DisplayUsage
  78.     WScript.Echo "Usage: disptree [--ADSPath|-a ROOT NODE]"
  79.     WScript.Echo "                      [--NoRecurse|-n]"
  80.     WScript.Echo "                      [--Help|-?]"
  81.     WScript.Echo ""
  82.     WScript.Echo " Example 1: disptree"
  83.     WScript.Echo " Example 2: disptree -a IIS://LocalHost/w3svc --NoRecurse"
  84.     WSCript.Quit    
  85. End Sub
  86.  
  87. Sub Display(Msg)
  88.     WScript.Echo Now & ". Error Code: " & Err & " --- " & Msg
  89. End Sub
  90.