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

  1. '''''''''''''''''''''''''''''''''''''''''''''
  2. '
  3. '  Web Server Creation Utility  
  4. '
  5. '''''''''''''''''''''''''''''''''''''''''''''
  6.  
  7. '  Description:
  8. '  ------------
  9. '  This sample admin script allows you to create a web server.
  10. '
  11. '  To Run:  
  12. '  -------
  13. '  This is the format for this script:
  14. '  
  15. '      cscript mkwebsrv.vbs <rootdir> [-n <instancenum>][-c <comment>][-p <portnum>][-X (don't start)]
  16. '  
  17. '  NOTE:  If you want to execute this script directly from Windows, use 
  18. '  'wscript' instead of 'cscript'. 
  19. '
  20. '''''''''''''''''''''''''''''''''''''''''''''
  21.  
  22. Option Explicit
  23.  
  24. ' Initialize error checking
  25. On Error Resume Next
  26.  
  27. ' Initialize variables
  28. Dim ArgCount, WRoot, WNumber, WComment, WPort, BindingsList, ServerRun
  29. Dim ServiceObj, ServerObj, VDirObj
  30.  
  31. ' Default values
  32. ArgCount = 0
  33. WRoot = ""
  34. WNumber = 10
  35. WComment = "SampleServer"
  36. BindingsList = Array(0)
  37. BindingsList(0) = ":84:"
  38. WPort = BindingsList  ' Port property is a collection of port bindings
  39. ServerRun = True
  40.  
  41.   ' ** Parse Command Line
  42.  
  43.     ' Loop through arguments
  44.     While ArgCount < Wscript.Arguments.Count
  45.       
  46.       ' Determine switches used
  47.       Select Case Wscript.Arguments(ArgCount)
  48.  
  49.          Case "-n":   ' Set server instance number
  50.             ' Move to next arg, which should be parameter
  51.             ArgCount =  ArgCount + 1  
  52.             If ArgCount => Wscript.Arguments.Count Then
  53.                Call UsageMsg
  54.             Else
  55.                WNumber = Wscript.Arguments(ArgCount)
  56.             End If
  57.  
  58.          Case "-c":   ' Set server comment (friendly name)
  59.             ' Move to next arg, which should be parameter
  60.             ArgCount =  ArgCount + 1  
  61.             If ArgCount => Wscript.Arguments.Count Then
  62.                Call UsageMsg
  63.             Else
  64.                WComment = Wscript.Arguments(ArgCount)
  65.             End If
  66.  
  67.          Case "-p":   ' Port binding
  68.             ' Move to next arg, which should be parameter
  69.             ArgCount =  ArgCount + 1  
  70.             If ArgCount => Wscript.Arguments.Count Then
  71.                Call UsageMsg
  72.             Else
  73.                BindingsList(0) = ":" & Wscript.Arguments(ArgCount) & ":"
  74.                WPort = BindingsList   '  Takes collection as value
  75.             End If
  76.  
  77.          Case "-X":   ' Do NOT start the server upon creation
  78.             ServerRun = False
  79.  
  80.          Case "-h", "-?", "/?":
  81.             Call UsageMsg
  82.  
  83.          Case Else:
  84.             If WRoot <> "" Then  ' Only one name allowed
  85.                Call UsageMsg
  86.             Else
  87.                WRoot = Wscript.Arguments(ArgCount)
  88.             End If
  89.  
  90.       End Select
  91.  
  92.       ' Move pointer to next argument
  93.       ArgCount = ArgCount + 1
  94.  
  95.     Wend
  96.  
  97.  
  98.   ' Screen to make sure WRoot was set
  99.   If WRoot = "" Then Call UsageMsg  
  100.  
  101.  
  102.   ' ** Create Server **
  103.   ' First, create instance of Web service
  104.   Set ServiceObj = GetObject("IIS://Localhost/W3SVC")
  105.   
  106.   ' Second, create a new virtual server at the service
  107.   Set ServerObj = ServiceObj.Create("IIsWebServer", WNumber)
  108.  
  109.     ' Error creating?
  110.     If (Err.Number <> 0) Then    ' Error!
  111.        Wscript.Echo "Error:  ADSI Create failed to create server."
  112.        Wscript.Quit
  113.     End If
  114.   
  115.   ' Next, configure new server
  116.   ServerObj.ServerSize = 1   ' Medium-sized server
  117.   ServerObj.ServerComment = WComment
  118.   ServerObj.ServerBindings = WPort
  119.  
  120.   ' Write info back to Metabase
  121.   ServerObj.SetInfo
  122.  
  123.  
  124.   ' Finally, create virtual root directory
  125.   Set VDirObj = ServerObj.Create("IIsWebVirtualDir", "ROOT")
  126.  
  127.     ' Error creating?
  128.     If (Err.Number <> 0) Then    ' Error!
  129.        Wscript.Echo "Error:  ADSI Create failed to create virtual directory."
  130.        Wscript.Quit
  131.     End If
  132.  
  133.   ' Configure new virtual root
  134.   VDirObj.Path = WRoot
  135.   VDirObj.AccessRead = True
  136.   VDirObj.AccessWrite = True
  137.   VDirObj.EnableDirBrowsing = True
  138.  
  139.   ' Write info back to Metabase
  140.   VDirObj.SetInfo
  141.  
  142.   ' Success!
  143.   Wscript.Echo "Created: Web server '" & WComment & "' (Physical root=" & WRoot & ", Port=" & WPort(0) & ")."
  144.  
  145.   ' Start new server?
  146.   If ServerRun = True Then
  147.      ServerObj.Start
  148.  
  149.        ' Error starting?
  150.        If (Err.Number <> 0) Then    ' Error!
  151.           Wscript.Echo "Error:  Start failed to start server."
  152.           Wscript.Quit
  153.        End If
  154.  
  155.      Wscript.Echo "Started: Web server '" & WComment & "' (Physical root=" & WRoot & ", Port=" & WPort(0) & ")."
  156.      Wscript.Quit(0)
  157.   End If
  158.  
  159.  
  160.  
  161.  
  162. ' Displays usage message, then QUITS
  163. Sub UsageMsg
  164.    Wscript.Echo "Usage:  cscript mkwebsrv.vbs <rootdir> [-n <instancenum>][-c <comment>][-p <portnum>][-X (don't start)]"
  165.    Wscript.Quit
  166. End Sub
  167.  
  168.  
  169.  
  170.  
  171.  
  172.