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.

1131 lines
42 KiB

  1. '
  2. ' Copyright (c) Microsoft Corporation. All rights reserved.
  3. '
  4. ' VBScript Source File
  5. '
  6. ' Script Name: IIsWeb.vbs
  7. '
  8. Option Explicit
  9. On Error Resume Next
  10. ' Error codes
  11. Const ERR_OK = 0
  12. Const ERR_GENERAL_FAILURE = 1
  13. '''''''''''''''''''''
  14. ' Messages
  15. Const L_BindingConflict_ErrorMessage = "(ERROR: BINDING CONFLICT)"
  16. Const L_SitesNotFound_ErrorMessage = "Site(s) not found."
  17. Const L_IsAlready_Message = "is already"
  18. Const L_ServerIs_Message = "server is"
  19. Const L_HasBeen_Message = "has been"
  20. Const L_NotFound_Message = "not found"
  21. Const L_All_Text = "ALL"
  22. Const L_AllUnassigned_Text = "ALL UNASSIGNED"
  23. Const L_NotSpecified_Text = "NOT SPECIFIED"
  24. Const L_Server_Text = "Server"
  25. Const L_SiteName_Text = "Site Name"
  26. Const L_MetabasePath_Message = "Metabase Path"
  27. Const L_IP_Text = "IP"
  28. Const L_Host_Text = "Host"
  29. Const L_Port_Text = "Port"
  30. Const L_Root_Text = "Root"
  31. Const L_Status_Text = "Status"
  32. Const L_NA_Text = "N/A"
  33. Const L_Error_ErrorMessage = "Error"
  34. Const L_GetRoot_ErrorMessage = "Could not obtaing ROOT virtual dir of site"
  35. Const L_RecursiveDel_ErrorMessage = "Could not recursively delete application site"
  36. Const L_SiteGet_ErrorMessage = "Could not obtain web site"
  37. Const L_Stop_ErrorMessage = "Could not stop web site"
  38. Const L_SiteDel_ErrorMessage = "Could not delete web site"
  39. Const L_GetWebServer_ErrorMessage = "Error trying to obtain WebServer object."
  40. Const L_CannotCreateDir_ErrorMessage = "Could not create root directory"
  41. Const L_DirFormat_ErrorMessage = "Root directory format unknown. Please use the '<drive>:\<path>' format."
  42. Const L_AppCreate_ErrorMessage = "Error trying to create pooled-proc application on new website"
  43. Const L_CannotStart_Message = "Server cannot be started in its current state"
  44. Const L_CannotStop_Message = "Server cannot be stopped in its current state"
  45. Const L_CannotPause_Message = "Server cannot be paused in its current state"
  46. Const L_CannotControl_ErrorMessage = "Server cannot be controled in its current state"
  47. Const L_FailChange_ErrorMessage = "Failed to change status of server."
  48. Const L_OperationRequired_ErrorMessage = "Please specify an operation before the arguments."
  49. Const L_MinInfoNeeded_ErrorMessage = "Need at least <root> to create a site."
  50. Const L_NotEnoughParams_ErrorMessage = "Not enough parameters."
  51. Const L_Query_ErrorMessage = "Error occurred while querying WMI provider."
  52. Const L_OnlyOneOper_ErrorMessage = "Please specify only one operation at a time."
  53. Const L_ServerInstance_ErrorMessage = "Error trying to create a new web server instance."
  54. Const L_ServerPut_ErrorMessage = "Error trying to save new web server instance."
  55. Const L_VDirInstance_ErrorMessage = "Error trying to create a new virtual directory instance."
  56. Const L_VDirPut_ErrorMessage = "Error trying to save new virtual directory instance."
  57. Const L_ScriptHelper_ErrorMessage = "Could not create an instance of the IIsScriptHelper object."
  58. Const L_ChkScpHelperReg_ErrorMessage = "Please register the Microsoft.IIsScriptHelper component."
  59. Const L_CmdLib_ErrorMessage = "Unable to create instance of the CmdLib object."
  60. Const L_InvalidIP_ErrorMessage = "Invalid IP Address. Please check if it is well formated and belongs to this machine."
  61. Const L_InvalidPort_ErrorMessage = "Invalid port number."
  62. Const L_MapDrive_ErrorMessage = "Could not map network drive."
  63. Const L_PassWithoutUser_ErrorMessage = "Please specify /u switch before using /p."
  64. Const L_WMIConnect_ErrorMessage = "Could not connect to WMI provider."
  65. Const L_InvalidSwitch_ErrorMessage = "Invalid switch: "
  66. '''''''''''''''''''''
  67. ' Help
  68. ' General help messages
  69. Const L_SeeHelp_Message = "Type IIsWeb /? for help."
  70. Const L_SeeStartHelp_Message = "Type IIsWeb /start /? for help."
  71. Const L_SeeStopHelp_Message = "Type IIsWeb /stop /? for help."
  72. Const L_SeePauseHelp_Message = "Type IIsWeb /pause /? for help."
  73. Const L_SeeCreateHelp_Message = "Type IIsWeb /create /? for help."
  74. Const L_SeeDeleteHelp_Message = "Type IIsWeb /delete /? for help."
  75. Const L_SeeQueryHelp_Message = "Type IIsWeb /query /? for help."
  76. Const L_Help_HELP_General01_Text = "Description: Start, Stop, Pause, Delete, Query, or Create a Web Site"
  77. Const L_Help_HELP_General02_Text = "Syntax: IIsWeb [/s <server> [/u <username> [/p <password>]]] /<operation>"
  78. Const L_Help_HELP_General03_Text = " [arguments]"
  79. Const L_Help_HELP_General04_Text = "Parameters:"
  80. Const L_Help_HELP_General05_Text = ""
  81. Const L_Help_HELP_General06_Text = "Value Description"
  82. Const L_Help_HELP_General07_Text = "/s <server> Connect to machine <server> [Default: this system]"
  83. Const L_Help_HELP_General08_Text = "/u <username> Connect as <username> or <domain>\<username>"
  84. Const L_Help_HELP_General09_Text = " [Default: current user]"
  85. Const L_Help_HELP_General10_Text = "/p <password> Password for the <username> user"
  86. Const L_Help_HELP_General11_Text = "<operation> /start Starts a site(s) on given IIS Server."
  87. Const L_Help_HELP_General12_Text = " /stop Stops a site(s) from running on a given"
  88. Const L_Help_HELP_General13_Text = " IIS Server."
  89. Const L_Help_HELP_General14_Text = " /pause Pauses a site(s) that is running on a"
  90. Const L_Help_HELP_General15_Text = " given IIS Server."
  91. Const L_Help_HELP_General18_Text = " /delete Deletes IIS configuration from an existing"
  92. Const L_Help_HELP_General19_Text = " Web Site. Content will not be deleted."
  93. Const L_Help_HELP_General20_Text = " /create Creates a Web Site."
  94. Const L_Help_HELP_General21_Text = " /query Queries existing Web Sites."
  95. Const L_Help_HELP_General22_Text = "For detailed usage:"
  96. Const L_Help_HELP_General23_Text = "IIsWeb /start /?"
  97. Const L_Help_HELP_General24_Text = "IIsWeb /stop /?"
  98. Const L_Help_HELP_General25_Text = "IIsWeb /pause /?"
  99. Const L_Help_HELP_General27_Text = "IIsWeb /delete /?"
  100. Const L_Help_HELP_General28_Text = "IIsWeb /create /?"
  101. Const L_Help_HELP_General29_Text = "IIsWeb /query /?"
  102. ' Common to all status change commands
  103. Const L_Help_HELP_Status03_Text = "Parameters:"
  104. Const L_Help_HELP_Status09_Text = "<website> Use either the site name or metabase path to specify"
  105. Const L_Help_HELP_Status09p1_Text = " the site"
  106. Const L_Help_HELP_Status10_Text = "Examples:"
  107. ' Start help messages
  108. Const L_Help_HELP_Start01_Text = "Description: Starts a site(s) on a given IIS Server."
  109. Const L_Help_HELP_Start02_Text = "Syntax: IIsWeb [/s <server> [/u <username> [/p <password>]]] /start"
  110. Const L_Help_HELP_Start02p1_Text = " <website> [<website> ...]"
  111. Const L_Help_HELP_Start11_Text = "IIsWeb /start ""Default Web Site"""
  112. Const L_Help_HELP_Start12_Text = "IIsWeb /start w3svc/1"
  113. Const L_Help_HELP_Start13_Text = "IIsWeb /start w3svc/2 ""Default Web Site"" w3svc/10"
  114. Const L_Help_HELP_Start14_Text = "IIsWeb /s Server1 /u Administrator /p p@ssWOrd /start w3svc/4"
  115. ' Stop help messages
  116. Const L_Help_HELP_Stop01_Text = "Description: Stops a site(s) on a given IIS Server."
  117. Const L_Help_HELP_Stop02_Text = "Syntax: IIsWeb [/s <server> [/u <username> [/p <password>]]] /stop"
  118. Const L_Help_HELP_Stop02p1_Text = " <website> [<website> ...]"
  119. Const L_Help_HELP_Stop11_Text = "IIsWeb /stop ""Default Web Site"""
  120. Const L_Help_HELP_Stop12_Text = "IIsWeb /stop w3svc/1"
  121. Const L_Help_HELP_Stop13_Text = "IIsWeb /stop w3svc/2 ""Default Web Site"" w3svc/10"
  122. Const L_Help_HELP_Stop14_Text = "IIsWeb /s Server1 /u Administrator /p p@ssWOrd /stop w3svc/4"
  123. ' Pause help messages
  124. Const L_Help_HELP_Pause01_Text = "Description: Pauses a site(s) on a given IIS Server."
  125. Const L_Help_HELP_Pause02_Text = "Syntax: IIsWeb [/s <server> [/u <username> [/p <password>]]] /pause"
  126. Const L_Help_HELP_Pause02p1_Text = " <website> [<website> ...]"
  127. Const L_Help_HELP_Pause11_Text = "IIsWeb /pause ""Default Web Site"""
  128. Const L_Help_HELP_Pause12_Text = "IIsWeb /pause w3svc/1"
  129. Const L_Help_HELP_Pause13_Text = "IIsWeb /pause w3svc/2 ""Default Web Site"" w3svc/10"
  130. Const L_Help_HELP_Pause14_Text = "IIsWeb /s Server1 /u Administrator /p p@ssWOrd /pause w3svc/4"
  131. ' Delete help messages
  132. Const L_Help_HELP_Delete01_Text = "Description: Deletes IIS configuration for an existing web site. Content"
  133. Const L_Help_HELP_Delete01p1_Text = " will not be deleted."
  134. Const L_Help_HELP_Delete02_Text = "Syntax: IIsWeb [/s <server> [/u <username> [/p <password>]]] /delete"
  135. Const L_Help_HELP_Delete02p1_Text = " <website> [<website> ...]"
  136. Const L_Help_HELP_Delete11_Text = "IIsWeb /delete ""Default Web Site"""
  137. Const L_Help_HELP_Delete12_Text = "IIsWeb /delete w3svc/1"
  138. Const L_Help_HELP_Delete13_Text = "IIsWeb /delete w3svc/2 ""Default Web Site"" w3svc/10"
  139. Const L_Help_HELP_Delete14_Text = "IIsWeb /s Server1 /u Administrator /p p@ssWOrd /delete w3svc/4"
  140. ' Create help messages
  141. Const L_Help_HELP_Create01_Text = "Description: Creates a web site."
  142. Const L_Help_HELP_Create02_Text = "Syntax: IIsWeb [/s <server> [/u <username> [/p <password>]]] /create <root>"
  143. Const L_Help_HELP_Create02p1_Text = " <name> [/d <host>] [/b <port>] [/i <ip>] [/dontstart]"
  144. Const L_Help_HELP_Create09_Text = "<root> Root directory for the new server. If this directory"
  145. Const L_Help_HELP_Create09p1_Text = " does not exist, it will be created."
  146. Const L_Help_HELP_Create10_Text = "<name> The name that appears in the Microsoft Management"
  147. Const L_Help_HELP_Create10p1_Text = " Console (MMC)."
  148. Const L_Help_HELP_Create11_Text = "/d <host> The host name to assign to this site. WARNING: Only"
  149. Const L_Help_HELP_Create11p1_Text = " use host name if DNS is set up to find the server"
  150. Const L_Help_HELP_Create12_Text = "/b <port> The number of the port to which the new server should"
  151. Const L_Help_HELP_Create12p1_Text = " bind. [Default: 80]"
  152. Const L_Help_HELP_Create13_Text = "/i <ip> The IP address to assign to the new server."
  153. Const L_Help_HELP_Create13p1_Text = " [Default: All Unassigned]"
  154. Const L_Help_HELP_Create15_Text = "/dontstart Don't start this site after it is created."
  155. Const L_Help_HELP_Create22_Text = "IIsWeb /create c:\inetpub\wwwroot ""My Site"" /b 80"
  156. Const L_Help_HELP_Create23_Text = "IIsWeb /s Server1 /u Administrator /p p@assWOrd /create c:\inetpub\wwwroot"
  157. Const L_Help_HELP_Create23p1_Text = " ""My Site"""
  158. Const L_Help_HELP_Create24_Text = "IIsWeb /create c:\inetpub\wwwroot ""My Site"" /i 172.30.163.244 /b 80"
  159. Const L_Help_HELP_Create24p1_Text = " /d www.mysite.com"
  160. ' Query help messages
  161. Const L_Help_HELP_Query01_Text = "Description: Queries existing web sites."
  162. Const L_Help_HELP_Query02_Text = "Syntax: IIsWeb [/s <server> [/u <username> [/p <password>]]] /query"
  163. Const L_Help_HELP_Query02p1_Text = " [<website> ...]"
  164. Const L_Help_HELP_Query11_Text = "IIsWeb /query ""Default Web Site"""
  165. Const L_Help_HELP_Query12_Text = "IIsWeb /query w3svc/1"
  166. Const L_Help_HELP_Query13_Text = "IIsWeb /query"
  167. Const L_Help_HELP_Query14_Text = "IIsWeb /query ""Default Web Site"" ""Sample Site"" w3svc/1"
  168. Const L_Help_HELP_Query15_Text = "IIsWeb /s Server1 /u Administrator /p p@ssW0rd /query ""Default Web Site"""
  169. ' Status
  170. Const L_Started_Text = "started"
  171. Const L_Stopped_Text = "stopped"
  172. Const L_Paused_Text = "paused"
  173. Const L_Continued_Text = "continued"
  174. Const L_Deleted_Text = "deleted"
  175. ''''''''''''''''''''''''
  176. Dim SiteStatus
  177. SiteStatus = Array("", "", L_Started_Text, "", L_Stopped_Text, "", L_Paused_Text, L_Continued_Text, L_Deleted_Text)
  178. ' Operation codes
  179. Const OPER_START = 1
  180. Const OPER_STOP = 2
  181. Const OPER_PAUSE = 3
  182. Const OPER_DELETE = 4
  183. Const OPER_CREATE = 5
  184. Const OPER_QUERY = 6
  185. ' ServerState codes
  186. Const SERVER_STARTING = 1
  187. Const SERVER_STARTED = 2
  188. Const SERVER_STOPPING = 3
  189. Const SERVER_STOPPED = 4
  190. Const SERVER_PAUSING = 5
  191. Const SERVER_PAUSED = 6
  192. Const SERVER_CONTINUING = 7
  193. '
  194. ' Main block
  195. '
  196. Dim oScriptHelper, oCmdLib
  197. Dim strServer, strUser, strPassword, strSite
  198. Dim intOperation, intResult
  199. Dim strRoot, strName, strHost, strPort, strIP
  200. Dim bDontStart
  201. Dim aArgs, arg
  202. Dim strCmdLineOptions
  203. Dim oError
  204. ' Default values
  205. strServer = "."
  206. strUser = ""
  207. strPassword = ""
  208. intOperation = 0
  209. strSite = ""
  210. strName = ""
  211. bDontStart = False
  212. ' Instantiate script helper object
  213. Set oScriptHelper = CreateObject("Microsoft.IIsScriptHelper")
  214. If Err.Number <> 0 Then
  215. WScript.Echo L_ScriptHelper_ErrorMessage
  216. WScript.Echo L_ChkScpHelperReg_ErrorMessage
  217. WScript.Quit(ERR_GENERAL_FAILURE)
  218. End If
  219. Set oScriptHelper.ScriptHost = WScript
  220. ' Check if we are being run with cscript.exe instead of wscript.exe
  221. oScriptHelper.CheckScriptEngine
  222. ' Minimum number of parameters must exist
  223. If WScript.Arguments.Count < 1 Then
  224. WScript.Echo L_NotEnoughParams_ErrorMessage
  225. WScript.Echo L_SeeHelp_Message
  226. WScript.Quit(ERR_GENERAL_FAILURE)
  227. End If
  228. strCmdLineOptions = "[server:s:1;user:u:1;password:p:1];start::n;stop::n;pause::n;delete::n;" & _
  229. "[create:c:1;domain:d:1;port:b:1;ip:i:1;dontstart::0];query:q:n"
  230. Set oError = oScriptHelper.ParseCmdLineOptions(strCmdLineOptions)
  231. If Not oError Is Nothing Then
  232. If oError.ErrorCode = oScriptHelper.ERROR_NOT_ENOUGH_ARGS Then
  233. ' Not enough arguments for a specified switch
  234. WScript.Echo L_NotEnoughParams_ErrorMessage
  235. If oError.SwitchName = "create" Then
  236. WScript.Echo L_SeeCreateHelp_Message
  237. Else
  238. WScript.Echo L_SeeHelp_Message
  239. End If
  240. Else
  241. ' Invalid switch
  242. WScript.Echo L_InvalidSwitch_ErrorMessage & oError.SwitchName
  243. WScript.Echo L_SeeHelp_Message
  244. End If
  245. WScript.Quit(ERR_GENERAL_FAILURE)
  246. End If
  247. If oScriptHelper.GlobalHelpRequested Then
  248. DisplayHelpMessage
  249. WScript.Quit(ERR_OK)
  250. End If
  251. For Each arg In oScriptHelper.Switches
  252. Select Case arg
  253. Case "server"
  254. ' Server information
  255. strServer = oScriptHelper.GetSwitch(arg)
  256. Case "user"
  257. ' User information
  258. strUser = oScriptHelper.GetSwitch(arg)
  259. Case "password"
  260. ' Password information
  261. strPassword = oScriptHelper.GetSwitch(arg)
  262. Case "start"
  263. If (intOperation <> 0) Then
  264. WScript.Echo L_OnlyOneOper_ErrorMessage
  265. WScript.Echo L_SeeHelp_Message
  266. WScript.Quit(ERR_GENERAL_FAILURE)
  267. End If
  268. intOperation = OPER_START
  269. If oScriptHelper.IsHelpRequested(arg) Then
  270. DisplayStartHelpMessage
  271. WScript.Quit(ERR_OK)
  272. End If
  273. aArgs = oScriptHelper.GetSwitch(arg)
  274. If UBound(aArgs) = -1 Then
  275. WScript.Echo L_NotEnoughParams_ErrorMessage
  276. WScript.Echo L_SeeStartHelp_Message
  277. WScript.Quit(ERR_GENERAL_FAILURE)
  278. End If
  279. Case "stop"
  280. If (intOperation <> 0) Then
  281. WScript.Echo L_OnlyOneOper_ErrorMessage
  282. WScript.Echo L_SeeHelp_Message
  283. WScript.Quit(ERR_GENERAL_FAILURE)
  284. End If
  285. intOperation = OPER_STOP
  286. If oScriptHelper.IsHelpRequested(arg) Then
  287. DisplayStopHelpMessage
  288. WScript.Quit(ERR_OK)
  289. End If
  290. aArgs = oScriptHelper.GetSwitch(arg)
  291. If UBound(aArgs) = -1 Then
  292. WScript.Echo L_NotEnoughParams_ErrorMessage
  293. WScript.Echo L_SeeStopHelp_Message
  294. WScript.Quit(ERR_GENERAL_FAILURE)
  295. End If
  296. Case "pause"
  297. If (intOperation <> 0) Then
  298. WScript.Echo L_OnlyOneOper_ErrorMessage
  299. WScript.Echo L_SeeHelp_Message
  300. WScript.Quit(ERR_GENERAL_FAILURE)
  301. End If
  302. intOperation = OPER_PAUSE
  303. If oScriptHelper.IsHelpRequested(arg) Then
  304. DisplayPauseHelpMessage
  305. WScript.Quit(ERR_OK)
  306. End If
  307. aArgs = oScriptHelper.GetSwitch(arg)
  308. If UBound(aArgs) = -1 Then
  309. WScript.Echo L_NotEnoughParams_ErrorMessage
  310. WScript.Echo L_SeePauseHelp_Message
  311. WScript.Quit(ERR_GENERAL_FAILURE)
  312. End If
  313. Case "create"
  314. If (intOperation <> 0) Then
  315. WScript.Echo L_OnlyOneOper_ErrorMessage
  316. WScript.Echo L_SeeHelp_Message
  317. WScript.Quit(ERR_GENERAL_FAILURE)
  318. End If
  319. intOperation = OPER_CREATE
  320. If oScriptHelper.IsHelpRequested(arg) Then
  321. DisplayCreateHelpMessage
  322. WScript.Quit(ERR_OK)
  323. End If
  324. strRoot = oScriptHelper.GetSwitch(arg)
  325. aArgs = oScriptHelper.NamedArguments
  326. If strRoot = "" Or UBound(aArgs) = -1 Then
  327. WScript.Echo L_NotEnoughParams_ErrorMessage
  328. WScript.Echo L_SeeCreateHelp_Message
  329. WScript.Quit(ERR_GENERAL_FAILURE)
  330. End If
  331. strName = aArgs(0)
  332. strHost = oScriptHelper.GetSwitch("domain")
  333. strPort = oScriptHelper.GetSwitch("port")
  334. strIP = oScriptHelper.GetSwitch("ip")
  335. If oScriptHelper.Switches.Exists("dontstart") Then
  336. bDontStart = True
  337. End If
  338. Case "delete"
  339. If (intOperation <> 0) Then
  340. WScript.Echo L_OnlyOneOper_ErrorMessage
  341. WScript.Echo L_SeeHelp_Message
  342. WScript.Quit(ERR_GENERAL_FAILURE)
  343. End If
  344. intOperation = OPER_DELETE
  345. If oScriptHelper.IsHelpRequested(arg) Then
  346. DisplayDeleteHelpMessage
  347. WScript.Quit(ERR_OK)
  348. End If
  349. aArgs = oScriptHelper.GetSwitch(arg)
  350. If UBound(aArgs) = -1 Then
  351. WScript.Echo L_NotEnoughParams_ErrorMessage
  352. WScript.Echo L_SeeDeleteHelp_Message
  353. WScript.Quit(ERR_GENERAL_FAILURE)
  354. End If
  355. Case "query"
  356. If (intOperation <> 0) Then
  357. WScript.Echo L_OnlyOneOper_ErrorMessage
  358. WScript.Echo L_SeeHelp_Message
  359. WScript.Quit(ERR_GENERAL_FAILURE)
  360. End If
  361. intOperation = OPER_QUERY
  362. If oScriptHelper.IsHelpRequested(arg) Then
  363. DisplayQueryHelpMessage
  364. WScript.Quit(ERR_OK)
  365. End If
  366. aArgs = oScriptHelper.GetSwitch(arg)
  367. End Select
  368. Next
  369. ' Check Parameters
  370. If intOperation = 0 Then
  371. WScript.Echo L_OperationRequired_ErrorMessage
  372. WScript.Echo L_SeeHelp_Message
  373. WScript.Quit(ERR_GENERAL_FAILURE)
  374. End If
  375. ' Check if /p is specified but /u isn't. In this case, we should bail out with an error
  376. If oScriptHelper.Switches.Exists("password") And Not oScriptHelper.Switches.Exists("user") Then
  377. WScript.Echo L_PassWithoutUser_ErrorMessage
  378. WScript.Quit(ERR_GENERAL_FAILURE)
  379. End If
  380. ' Check if /u is specified but /p isn't. In this case, we should ask for a password
  381. If oScriptHelper.Switches.Exists("user") And Not oScriptHelper.Switches.Exists("password") Then
  382. Set oCmdLib = CreateObject("Microsoft.CmdLib")
  383. Set oCmdLib.ScriptingHost = WScript.Application
  384. If Err.Number Then
  385. WScript.Echo L_CmdLib_ErrorMessage
  386. WScript.Quit(Err.Number)
  387. Else
  388. strPassword = oCmdLib.GetPassword
  389. Set oCmdLib = Nothing
  390. End If
  391. End If
  392. ' Initializes authentication with remote machine
  393. intResult = oScriptHelper.InitAuthentication(strServer, strUser, strPassword)
  394. If intResult <> 0 Then
  395. WScript.Quit(intResult)
  396. End If
  397. ' Choose operation
  398. Select Case intOperation
  399. Case OPER_START
  400. intResult = ChangeWebSiteStatus(aArgs, SERVER_STARTED)
  401. Case OPER_STOP
  402. intResult = ChangeWebSiteStatus(aArgs, SERVER_STOPPED)
  403. Case OPER_PAUSE
  404. intResult = ChangeWebSiteStatus(aArgs, SERVER_PAUSED)
  405. Case OPER_DELETE
  406. intResult = DeleteWebSite(aArgs)
  407. Case OPER_CREATE
  408. 'intResult = CreateWebSite(aArgs)
  409. intResult = CreateWebSite(strRoot, strName, strHost, strPort, strIP, bDontStart)
  410. Case OPER_QUERY
  411. intResult = QueryWebSite(aArgs)
  412. End Select
  413. ' Return value to command processor
  414. WScript.Quit(intResult)
  415. '''''''''''''''''''''''''
  416. ' End Of Main Block
  417. '''''''''''''''''''''
  418. '''''''''''''''''''''''''''
  419. ' DisplayHelpMessage
  420. '''''''''''''''''''''''''''
  421. Sub DisplayHelpMessage()
  422. WScript.Echo L_Help_HELP_General01_Text
  423. WScript.Echo
  424. WScript.Echo L_Help_HELP_General02_Text
  425. WScript.Echo L_Help_HELP_General03_Text
  426. WScript.Echo
  427. WScript.Echo L_Help_HELP_General04_Text
  428. WScript.Echo L_Help_HELP_General05_Text
  429. WScript.Echo L_Help_HELP_General06_Text
  430. WScript.Echo L_Help_HELP_General07_Text
  431. WScript.Echo L_Help_HELP_General08_Text
  432. WScript.Echo L_Help_HELP_General09_Text
  433. WScript.Echo L_Help_HELP_General10_Text
  434. WScript.Echo L_Help_HELP_General11_Text
  435. WScript.Echo L_Help_HELP_General12_Text
  436. WScript.Echo L_Help_HELP_General13_Text
  437. WScript.Echo L_Help_HELP_General14_Text
  438. WScript.Echo L_Help_HELP_General15_Text
  439. WScript.Echo L_Help_HELP_General18_Text
  440. WScript.Echo L_Help_HELP_General19_Text
  441. WScript.Echo L_Help_HELP_General20_Text
  442. WScript.Echo L_Help_HELP_General21_Text
  443. WScript.Echo
  444. WScript.Echo L_Help_HELP_General22_Text
  445. WScript.Echo
  446. WScript.Echo L_Help_HELP_General23_Text
  447. WScript.Echo L_Help_HELP_General24_Text
  448. WScript.Echo L_Help_HELP_General25_Text
  449. WScript.Echo L_Help_HELP_General27_Text
  450. WScript.Echo L_Help_HELP_General28_Text
  451. WScript.Echo L_Help_HELP_General29_Text
  452. End Sub
  453. Sub DisplayStartHelpMessage()
  454. WScript.Echo L_Help_HELP_Start01_Text
  455. WScript.Echo
  456. WScript.Echo L_Help_HELP_Start02_Text
  457. WScript.Echo L_Help_HELP_Start02p1_Text
  458. WScript.Echo
  459. WScript.Echo L_Help_HELP_Status03_Text
  460. WScript.Echo
  461. WScript.Echo L_Help_HELP_General06_Text
  462. WScript.Echo L_Help_HELP_General07_Text
  463. WScript.Echo L_Help_HELP_General08_Text
  464. WScript.Echo L_Help_HELP_General09_Text
  465. WScript.Echo L_Help_HELP_General10_Text
  466. WScript.Echo L_Help_HELP_Status09_Text
  467. WScript.Echo L_Help_HELP_Status09p1_Text
  468. WScript.Echo
  469. WScript.Echo
  470. WScript.Echo L_Help_HELP_Status10_Text
  471. WScript.Echo
  472. WScript.Echo L_Help_HELP_Start11_Text
  473. WScript.Echo L_Help_HELP_Start12_Text
  474. WScript.Echo L_Help_HELP_Start13_Text
  475. WScript.Echo L_Help_HELP_Start14_Text
  476. End Sub
  477. Sub DisplayStopHelpMessage()
  478. WScript.Echo L_Help_HELP_Stop01_Text
  479. WScript.Echo
  480. WScript.Echo L_Help_HELP_Stop02_Text
  481. WScript.Echo L_Help_HELP_Stop02p1_Text
  482. WScript.Echo
  483. WScript.Echo L_Help_HELP_Status03_Text
  484. WScript.Echo
  485. WScript.Echo L_Help_HELP_General06_Text
  486. WScript.Echo L_Help_HELP_General07_Text
  487. WScript.Echo L_Help_HELP_General08_Text
  488. WScript.Echo L_Help_HELP_General09_Text
  489. WScript.Echo L_Help_HELP_General10_Text
  490. WScript.Echo L_Help_HELP_Status09_Text
  491. WScript.Echo L_Help_HELP_Status09p1_Text
  492. WScript.Echo
  493. WScript.Echo
  494. WScript.Echo L_Help_HELP_Status10_Text
  495. WScript.Echo
  496. WScript.Echo L_Help_HELP_Stop11_Text
  497. WScript.Echo L_Help_HELP_Stop12_Text
  498. WScript.Echo L_Help_HELP_Stop13_Text
  499. WScript.Echo L_Help_HELP_Stop14_Text
  500. End Sub
  501. Sub DisplayPauseHelpMessage()
  502. WScript.Echo L_Help_HELP_Pause01_Text
  503. WScript.Echo
  504. WScript.Echo L_Help_HELP_Pause02_Text
  505. WScript.Echo L_Help_HELP_Pause02p1_Text
  506. WScript.Echo
  507. WScript.Echo L_Help_HELP_Status03_Text
  508. WScript.Echo
  509. WScript.Echo L_Help_HELP_General06_Text
  510. WScript.Echo L_Help_HELP_General07_Text
  511. WScript.Echo L_Help_HELP_General08_Text
  512. WScript.Echo L_Help_HELP_General09_Text
  513. WScript.Echo L_Help_HELP_General10_Text
  514. WScript.Echo L_Help_HELP_Status09_Text
  515. WScript.Echo L_Help_HELP_Status09p1_Text
  516. WScript.Echo
  517. WScript.Echo
  518. WScript.Echo L_Help_HELP_Status10_Text
  519. WScript.Echo
  520. WScript.Echo L_Help_HELP_Pause11_Text
  521. WScript.Echo L_Help_HELP_Pause12_Text
  522. WScript.Echo L_Help_HELP_Pause13_Text
  523. WScript.Echo L_Help_HELP_Pause14_Text
  524. End Sub
  525. Sub DisplayDeleteHelpMessage()
  526. WScript.Echo L_Help_HELP_Delete01_Text
  527. WScript.Echo L_Help_HELP_Delete01p1_Text
  528. WScript.Echo
  529. WScript.Echo L_Help_HELP_Delete02_Text
  530. WScript.Echo L_Help_HELP_Delete02p1_Text
  531. WScript.Echo
  532. WScript.Echo L_Help_HELP_Status03_Text
  533. WScript.Echo
  534. WScript.Echo L_Help_HELP_General06_Text
  535. WScript.Echo L_Help_HELP_General07_Text
  536. WScript.Echo L_Help_HELP_General08_Text
  537. WScript.Echo L_Help_HELP_General09_Text
  538. WScript.Echo L_Help_HELP_General10_Text
  539. WScript.Echo L_Help_HELP_Status09_Text
  540. WScript.Echo L_Help_HELP_Status09p1_Text
  541. WScript.Echo
  542. WScript.Echo
  543. WScript.Echo L_Help_HELP_Status10_Text
  544. WScript.Echo
  545. WScript.Echo L_Help_HELP_Delete11_Text
  546. WScript.Echo L_Help_HELP_Delete12_Text
  547. WScript.Echo L_Help_HELP_Delete13_Text
  548. WScript.Echo L_Help_HELP_Delete14_Text
  549. End Sub
  550. Sub DisplayCreateHelpMessage()
  551. WScript.Echo L_Help_HELP_Create01_Text
  552. WScript.Echo
  553. WScript.Echo L_Help_HELP_Create02_Text
  554. WScript.Echo L_Help_HELP_Create02p1_Text
  555. WScript.Echo
  556. WScript.Echo L_Help_HELP_Status03_Text
  557. WScript.Echo
  558. WScript.Echo L_Help_HELP_General06_Text
  559. WScript.Echo L_Help_HELP_General07_Text
  560. WScript.Echo L_Help_HELP_General08_Text
  561. WScript.Echo L_Help_HELP_General09_Text
  562. WScript.Echo L_Help_HELP_General10_Text
  563. WScript.Echo L_Help_HELP_Create09_Text
  564. WScript.Echo L_Help_HELP_Create09p1_Text
  565. WScript.Echo L_Help_HELP_Create10_Text
  566. WScript.Echo L_Help_HELP_Create10p1_Text
  567. WScript.Echo L_Help_HELP_Create11_Text
  568. WScript.Echo L_Help_HELP_Create11p1_Text
  569. WScript.Echo L_Help_HELP_Create12_Text
  570. WScript.Echo L_Help_HELP_Create12p1_Text
  571. WScript.Echo L_Help_HELP_Create13_Text
  572. WScript.Echo L_Help_HELP_Create13p1_Text
  573. WScript.Echo L_Help_HELP_Create15_Text
  574. WScript.Echo
  575. WScript.Echo L_Help_HELP_Status10_Text
  576. WScript.Echo
  577. WScript.Echo L_Help_HELP_Create22_Text
  578. WScript.Echo L_Help_HELP_Create23_Text
  579. WScript.Echo L_Help_HELP_Create23p1_Text
  580. WScript.Echo L_Help_HELP_Create24_Text
  581. WScript.Echo L_Help_HELP_Create24p1_Text
  582. End Sub
  583. Sub DisplayQueryHelpMessage()
  584. WScript.Echo L_Help_HELP_Query01_Text
  585. WScript.Echo
  586. WScript.Echo L_Help_HELP_Query02_Text
  587. WScript.Echo L_Help_HELP_Query02p1_Text
  588. WScript.Echo
  589. WScript.Echo L_Help_HELP_Status03_Text
  590. WScript.Echo
  591. WScript.Echo L_Help_HELP_General06_Text
  592. WScript.Echo L_Help_HELP_General07_Text
  593. WScript.Echo L_Help_HELP_General08_Text
  594. WScript.Echo L_Help_HELP_General09_Text
  595. WScript.Echo L_Help_HELP_General10_Text
  596. WScript.Echo L_Help_HELP_Status09_Text
  597. WScript.Echo L_Help_HELP_Status09p1_Text
  598. WScript.Echo
  599. WScript.Echo
  600. WScript.Echo L_Help_HELP_Status10_Text
  601. WScript.Echo
  602. WScript.Echo L_Help_HELP_Query11_Text
  603. WScript.Echo L_Help_HELP_Query12_Text
  604. WScript.Echo L_Help_HELP_Query13_Text
  605. WScript.Echo L_Help_HELP_Query14_Text
  606. WScript.Echo L_Help_HELP_Query15_Text
  607. End Sub
  608. '''''''''''''''''''''''''''
  609. ' ChangeWebSiteStatus
  610. '
  611. ' Try to change the status of a site
  612. ' to the one specified
  613. '''''''''''''''''''''''''''
  614. Function ChangeWebSiteStatus(aArgs, newStatus)
  615. Dim Server, strSiteName
  616. Dim intResult, i, intNewStatus
  617. Dim aSites
  618. Dim providerObj
  619. On Error Resume Next
  620. oScriptHelper.WMIConnect
  621. If Err.Number Then
  622. WScript.Echo L_WMIConnect_ErrorMessage
  623. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  624. ChangeWebSiteStatus = Err.Number
  625. Exit Function
  626. End If
  627. Set providerObj = oScriptHelper.ProviderObj
  628. intResult = 0
  629. aSites = oScriptHelper.FindSite("Web", aArgs)
  630. If IsArray(aSites) Then
  631. If UBound(aSites) = -1 Then
  632. WScript.Echo L_SitesNotFound_ErrorMessage
  633. intResult = ERR_GENERAL_FAILURE
  634. End If
  635. Else
  636. ' Got duplicate sites. We should quit.
  637. ChangeWebSiteStatus = intResult
  638. Exit Function
  639. End If
  640. For i = LBound(aSites) to UBound(aSites)
  641. strSiteName = aSites(i)
  642. ' Grab site state before trying to start it
  643. Set Server = providerObj.Get("IIsWebServer='" & strSiteName & "'")
  644. If (Err.Number <> 0) Then
  645. WScript.Echo L_GetWebServer_ErrorMessage
  646. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  647. intResult = Err.Number
  648. End If
  649. If (Server.ServerState = newStatus) Then
  650. WScript.Echo L_Server_Text & " " & strSiteName & " " & L_IsAlready_Message & " " & _
  651. UCase(SiteStatus(newStatus))
  652. Else
  653. If (Server.ServerState = SERVER_STARTING or Server.ServerState = SERVER_STOPPING or _
  654. Server.ServerState = SERVER_PAUSING or Server.ServerState = SERVER_CONTINUING) Then
  655. WScript.Echo L_CannotControl_ErrorMessage
  656. intResult = ERR_GENERAL_FAILURE
  657. Else
  658. Select Case newStatus
  659. Case SERVER_STARTED
  660. If (Server.ServerState = SERVER_STOPPED) Then
  661. intNewStatus = SERVER_STARTED
  662. Server.Start
  663. Else
  664. If (Server.ServerState = SERVER_PAUSED) Then
  665. intNewStatus = SERVER_CONTINUING
  666. Server.Continue
  667. Else
  668. WScript.Echo strSiteName & ": " & L_CannotStart_Message & _
  669. "(" & L_ServerIs_Message & " " & SiteStatus(Server.ServerState) & ")"
  670. End If
  671. End If
  672. Case SERVER_STOPPED
  673. If (Server.ServerState = SERVER_STARTED) Then
  674. intNewStatus = SERVER_STOPPED
  675. Server.Stop
  676. Else
  677. WScript.Echo L_CannotStop_Message & " (" & L_ServerIs_Message & " " & _
  678. SiteStatus(Server.ServerState) & ")"
  679. End If
  680. Case SERVER_PAUSED
  681. If (Server.ServerState = SERVER_STARTED) Then
  682. intNewStatus = SERVER_PAUSED
  683. Server.Pause
  684. Else
  685. WScript.Echo L_CannotPause_Message & " (" & L_ServerIs_Message & " " & _
  686. SiteStatus(Server.ServerState) & ")"
  687. End If
  688. Case Else
  689. WScript.Echo "!!! BUG BUG: unexpected state"
  690. End Select
  691. ' Error checking
  692. If (Err.Number <> 0) Then
  693. WScript.Echo L_FailChange_ErrorMessage & " " & strSite
  694. WScript.Echo L_Error_ErrorMessage& " &H" & Hex(Err.Number) & ": " & Err.Description
  695. intResult = Err.Number
  696. Else
  697. WScript.Echo L_Server_Text & " " & strSiteName & " " & L_HasBeen_Message & " " & _
  698. UCase(SiteStatus(intNewStatus))
  699. End If
  700. End If
  701. End If
  702. Next
  703. Set Server = Nothing
  704. ChangeWebSiteStatus = intResult
  705. End Function
  706. '''''''''''''''''''''''''''
  707. ' DeleteWebSite
  708. '''''''''''''''''''''''''''
  709. Function DeleteWebSite(aArgs)
  710. Dim strSiteName
  711. Dim RootVDirObj, WebServerObj
  712. Dim aSites
  713. Dim providerObj
  714. On Error Resume Next
  715. oScriptHelper.WMIConnect
  716. If Err.Number Then
  717. WScript.Echo L_WMIConnect_ErrorMessage
  718. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  719. DeleteWebSite = Err.Number
  720. Exit Function
  721. End If
  722. Set providerObj = oScriptHelper.ProviderObj
  723. aSites = oScriptHelper.FindSite("Web", aArgs)
  724. If IsArray(aSites) Then
  725. If UBound(aSites) = -1 Then
  726. WScript.Echo L_SitesNotFound_ErrorMessage
  727. intResult = ERR_GENERAL_FAILURE
  728. End If
  729. Else
  730. ' Got duplicate sites. We should quit.
  731. ChangeWebSiteStatus = intResult
  732. Exit Function
  733. End If
  734. For Each strSiteName in aSites
  735. ' First delete application in this site
  736. Set RootVDirObj = providerObj.Get("IIsWebVirtualDir='" & strSiteName & "/ROOT'")
  737. If (Err.Number <> 0) Then
  738. WScript.Echo L_GetRoot_ErrorMessage & " " & strSiteName
  739. WScript.Echo L_Error_ErrorMessage& " &H" & Hex(Err.Number) & ": " & Err.Description
  740. DeleteWebSite = Err.Number
  741. Exit Function
  742. End If
  743. RootVDirObj.AppDelete(True)
  744. If (Err.Number <> 0) Then
  745. WScript.Echo L_RecursiveDel_ErrorMessage & " " & strSiteName
  746. WScript.Echo L_Error_ErrorMessage& " &H" & Hex(Err.Number) & ": " & Err.Description
  747. DeleteWebSite = Err.Number
  748. Exit Function
  749. End If
  750. ' Next, stop and delete the web site itself
  751. Set WebServerObj = providerObj.Get("IIsWebServer='" & strSiteName & "'")
  752. If (Err.Number <> 0) Then
  753. WScript.Echo L_SiteGet_ErrorMessage & " " & strSiteName
  754. WScript.Echo L_Error_ErrorMessage& " &H" & Hex(Err.Number) & ": " & Err.Description
  755. DeleteWebSite = Err.Number
  756. Exit Function
  757. End If
  758. WebServerObj.Stop
  759. If (Err.Number <> 0) Then
  760. WScript.Echo L_Stop_ErrorMessage & " " & strSiteName
  761. WScript.Echo L_Error_ErrorMessage& " &H" & Hex(Err.Number) & ": " & Err.Description
  762. DeleteWebSite = Err.Number
  763. Exit Function
  764. End If
  765. WebServerObj.Delete_
  766. If (Err.Number <> 0) Then
  767. WScript.Echo L_SiteDel_ErrorMessage & " " & strSiteName
  768. WScript.Echo L_Error_ErrorMessage& " &H" & Hex(Err.Number) & ": " & Err.Description
  769. DeleteWebSite = Err.Number
  770. Exit Function
  771. End If
  772. WScript.Echo L_Server_Text & " " & strSiteName & " " & L_HasBeen_Message & " " & UCase(SiteStatus(8)) & "."
  773. Next
  774. DeleteWebSite = ERR_OK
  775. End Function
  776. '''''''''''''''''''''''''''
  777. ' CreateWebSite
  778. '''''''''''''''''''''''''''
  779. Function CreateWebSite(strRoot, strName, strHost, strPort, strIP, bDontStart)
  780. Dim strSitePath
  781. Dim strSiteObjPath
  782. Dim Bindings
  783. Dim objPath, serviceObj
  784. Dim serverObj, vdirObj
  785. Dim strStatus
  786. Dim providerObj
  787. On Error Resume Next
  788. ' Default port
  789. If (strPort = "") Then strPort = "80"
  790. ' Verify port number
  791. If Not oScriptHelper.IsValidPortNumber(strPort) Then
  792. WScript.Echo L_InvalidPort_ErrorMessage
  793. CreateWebSite = ERR_GENERAL_FAILURE
  794. Exit Function
  795. End If
  796. ' Verify IP Address
  797. If strIP <> "" Then
  798. If Not oScriptHelper.IsValidIPAddress(strIP) Then
  799. WScript.Echo L_InvalidIP_ErrorMessage
  800. CreateWebSite = ERR_GENERAL_FAILURE
  801. Exit Function
  802. End If
  803. End If
  804. ' Create physical directory
  805. oScriptHelper.CreateFSDir strRoot
  806. If Err.Number Then
  807. Select Case Err.Number
  808. Case &H8007000C
  809. WScript.Echo L_DirFormat_ErrorMessage
  810. WScript.Echo L_SeeCreateHelp_Message
  811. CreateWebSite = Err.Number
  812. Exit Function
  813. Case &H8007000F
  814. WScript.Echo L_MapDrive_ErrorMessage
  815. CreateWebSite = Err.Number
  816. Exit Function
  817. Case Else
  818. WScript.Echo L_CannotCreateDir_ErrorMessage
  819. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  820. CreateWebSite = Err.Number
  821. Exit Function
  822. End Select
  823. End If
  824. ' Time to connect to the IIS namespace
  825. oScriptHelper.WMIConnect
  826. If Err.Number Then
  827. WScript.Echo L_WMIConnect_ErrorMessage
  828. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  829. CreateWebSite = Err.Number
  830. Exit Function
  831. End If
  832. Set providerObj = oScriptHelper.ProviderObj
  833. ' Build binding object
  834. Bindings = Array(0)
  835. Set Bindings(0) = providerObj.get("ServerBinding").SpawnInstance_()
  836. Bindings(0).IP = strIP
  837. Bindings(0).Port = strPort
  838. Bindings(0).Hostname = strHost
  839. Set serviceObj = providerObj.Get("IIsWebService='W3SVC'")
  840. strSiteObjPath = serviceObj.CreateNewSite(strName, Bindings, strRoot)
  841. If Err Then
  842. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  843. CreateWebSite = Err.Number
  844. Exit Function
  845. End If
  846. ' Parse site ID out of WMI object path
  847. Set objPath = CreateObject("WbemScripting.SWbemObjectPath")
  848. objPath.Path = strSiteObjPath
  849. strSitePath = objPath.Keys.Item("")
  850. ' Set web virtual directory properties
  851. Set vdirObj = providerObj.Get("IIsWebVirtualDirSetting='" & strSitePath & "/ROOT'")
  852. vdirObj.AuthFlags = 5 ' AuthNTLM + AuthAnonymous
  853. vdirObj.EnableDefaultDoc = True
  854. vdirObj.DirBrowseFlags = &H4000003E ' date, time, size, extension, longdate
  855. vdirObj.AccessFlags = 513 ' read, script
  856. vdirObj.Put_()
  857. If Err Then
  858. WScript.Echo L_VDirPut_ErrorMessage
  859. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  860. providerObj.Delete(strSiteObjPath)
  861. CreateWebSite = Err.Number
  862. Exit Function
  863. End If
  864. ' Sometimes, the site is started right after its creation. Let's stop it at this point.
  865. Set serverObj = providerObj.Get("IIsWebServer='" & strSitePath & "'")
  866. serverObj.Stop
  867. ' Should we start the site?
  868. If Not bDontStart Then
  869. serverObj.Start
  870. ' If we cannot start the server, check for error stating the port is already in use
  871. If Err.Number = &H80070034 Or Err.Number = &H80070020 Then
  872. strStatus = UCase(SiteStatus(4)) & " " & L_BindingConflict_ErrorMessage
  873. Else
  874. strStatus = UCase(SiteStatus(2))
  875. End If
  876. Else
  877. strStatus = UCase(SiteStatus(4))
  878. End If
  879. If (strServer = ".") Then
  880. strServer = oScriptHelper.GetEnvironmentVar("%COMPUTERNAME%")
  881. End If
  882. If (strIP = "") Then strIP = L_AllUnassigned_Text
  883. If (strHost = "") Then strHost = L_NotSpecified_Text
  884. ' Post summary
  885. WScript.Echo L_Server_Text & Space(14 - Len(L_Server_Text)) & "= " & UCase(strServer)
  886. WScript.Echo L_SiteName_Text & Space(14 - Len(L_SiteName_Text)) & "= " & strName
  887. WScript.Echo L_MetabasePath_Message & Space(14 - Len(L_MetabasePath_Message)) & "= " & strSitePath
  888. WScript.Echo L_IP_Text & Space(14 - Len(L_IP_Text)) & "= " & strIP
  889. WScript.Echo L_Host_Text & Space(14 - Len(L_Host_Text)) & "= " & strHost
  890. WScript.Echo L_Port_Text & Space(14 - Len(L_Port_Text)) & "= " & strPort
  891. WScript.Echo L_Root_Text & Space(14 - Len(L_Root_Text)) & "= " & strRoot
  892. WScript.Echo L_Status_Text& Space(14 - Len(L_Status_Text)) & "= " & strStatus
  893. CreateWebSite = intResult
  894. End Function
  895. '''''''''''''''''''''''''''
  896. ' QueryWebSite
  897. '''''''''''''''''''''''''''
  898. Function QueryWebSite(aArgs)
  899. Dim Servers, Server, strQuery
  900. Dim ServerObj
  901. Dim i, intResult
  902. Dim bindings, binding
  903. Dim line, strIP, strPort, strHost, strState
  904. Dim providerObj
  905. Dim bFirstIteration
  906. On Error Resume Next
  907. oScriptHelper.WMIConnect
  908. If Err.Number Then
  909. WScript.Echo L_WMIConnect_ErrorMessage
  910. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  911. QueryWebSiteStatus = Err.Number
  912. Exit Function
  913. End If
  914. Set providerObj = oScriptHelper.ProviderObj
  915. intResult = 0
  916. If (UBound(aArgs) = -1) Then
  917. strQuery = "select Name, ServerComment, ServerBindings from IIsWebServerSetting"
  918. Else
  919. strQuery = "select Name, ServerComment, ServerBindings from IIsWebServerSetting where "
  920. For i = LBound(aArgs) to UBound(aArgs)
  921. strQuery = strQuery & "(Name='" & aArgs(i) & "' or ServerComment='" & aArgs(i) & "')"
  922. If (i <> UBound(aArgs)) Then
  923. strQuery = strQuery & " or "
  924. End If
  925. Next
  926. End If
  927. ' Semi-sync query. (flags = ForwardOnly Or ReturnImediately = &H30)
  928. Set Servers = providerObj.ExecQuery(strQuery, , &H30)
  929. If (Err.Number <> 0) Then
  930. WScript.Echo L_Query_ErrorMessage
  931. WScript.Echo L_Error_ErrorMessage& " &H" & Hex(Err.Number) & ": " & Err.Description
  932. WScript.Quit(Err.Number)
  933. End If
  934. bFirstIteration = True
  935. For Each Server in Servers
  936. bindings = Server.ServerBindings
  937. If bFirstIteration Then
  938. WScript.Echo L_SiteName_Text & " (" & L_MetabasePath_Message & ")" & _
  939. Space(30 - Len(L_SiteName_Text & L_MetabasePath_Message) + 3) & _
  940. L_Status_Text & Space(2) & L_IP_Text & Space(14) & L_Port_Text & Space(2) & L_Host_Text
  941. WScript.Echo "=============================================================================="
  942. End If
  943. ' Get server status from the element instance
  944. Set ServerObj = providerObj.Get("IIsWebServer='" & Server.Name & "'")
  945. strState = UCase(SiteStatus(ServerObj.ServerState))
  946. If (IsArray(bindings)) Then
  947. For i = LBound(bindings) to UBound(bindings)
  948. If (bindings(i).IP = "") Then
  949. strIP = L_All_Text
  950. Else
  951. strIP = bindings(i).IP
  952. End If
  953. strPort = bindings(i).Port
  954. If (bindings(i).Hostname = "") Then
  955. strHost = L_NA_Text
  956. Else
  957. strHost = bindings(i).Hostname
  958. End If
  959. ' If this is the first binding list, print server comment and server name
  960. If (i = LBound(bindings)) Then
  961. line = Server.ServerComment & " (" & Server.Name & ")" & _
  962. Space(30 - Len(Server.ServerComment & Server.Name) + 3) & strState & _
  963. Space(8 - Len(strState)) & strIP & Space(16 - Len(strIP)) & strPort & _
  964. Space(6 - Len(strPort)) & strHost
  965. Else
  966. line = Space(44) & strIP & Space(16 - Len(strIP)) & strPort & Space(6 - Len(strPort)) & strHost
  967. End If
  968. WScript.Echo line
  969. Next
  970. End If
  971. bFirstIteration = False
  972. Next
  973. If bFirstIteration Then
  974. WScript.Echo L_SitesNotFound_ErrorMessage
  975. End If
  976. End Function