Leaked source code of windows server 2003
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.

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