Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

171 lines
4.4 KiB

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