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.

467 lines
16 KiB

  1. '
  2. ' Copyright (c) Microsoft Corporation. All rights reserved.
  3. '
  4. ' VBScript Source File
  5. '
  6. ' Script Name: IIsApp.vbs
  7. '
  8. Option Explicit
  9. On Error Resume Next
  10. '''''''''''''''
  11. ' Notice
  12. WScript.Echo "This script has bugs that prevent it from working correctly."
  13. WScript.Quit(0)
  14. ' Error codes
  15. Const ERR_OK = 0
  16. Const ERR_GENERAL_FAILURE = 1
  17. '''''''''''''''''''''
  18. ' Messages
  19. Const L_Path_Text = "Path"
  20. Const L_HasBeen_Message = "has been"
  21. Const L_Imported_Text = "imported"
  22. Const L_Exported_Text = "exported"
  23. Const L_Error_ErrorMessage = "Error"
  24. Const L_GetComputerObject_ErrorMessage = "Could not get computer object"
  25. Const L_Import_ErrorMessage = "Error while importing configuration."
  26. Const L_Export_ErrorMessage = "Error while exporting configuration."
  27. Const L_NotEnoughParams_ErrorMessage = "Not enough parameters."
  28. 'Const L_OnlyOneOper_ErrorMessage = "Please, specify only one operation at a time."
  29. 'Const L_UnknownPerm_ErrorMessage = "Unknown physical directory permission"
  30. Const L_ScriptHelper_ErrorMessage = "Could not create an instance of the IIsScriptHelper object."
  31. Const L_ChkScpHelperReg_ErrorMessage = "Please, check if the Microsoft.IIsScriptHelper is registered."
  32. '''''''''''''''''''''
  33. ' Help
  34. Const L_Empty_Text = ""
  35. ' General help messages
  36. Const L_SeeHelp_Message = "Type IIsApp /? for help."
  37. Const L_SeeImportHelp_Message = "Type IIsApp /import /? for help."
  38. Const L_SeeExportHelp_Message = "Type IIsApp /export /? for help."
  39. Const L_Help_HELP_General01_Text = "Description: quickly create, delete, load, or unload an ""Application"""
  40. Const L_Help_HELP_General01p1_Text = " on a Web site, Virtual Directory or Directory."
  41. Const L_Help_HELP_General02_Text = "Syntax: IIsApp [/s <server>] [/u <username>] [/p <password>] /<operation>"
  42. Const L_Help_HELP_General03_Text = " <application>"
  43. Const L_Help_HELP_General04_Text = "Parameters:"
  44. Const L_Help_HELP_General05_Text = ""
  45. Const L_Help_HELP_General06_Text = "Value Description"
  46. Const L_Help_HELP_General07_Text = "/s <server> Connect to machine <server> [Default: this system]"
  47. Const L_Help_HELP_General08_Text = "/u <username> Connect as <username> or <domain>\<username>"
  48. Const L_Help_HELP_General09_Text = " [Default: current user]"
  49. Const L_Help_HELP_General10_Text = "/p <password> Password for the <username> user"
  50. Const L_Help_HELP_General11_Text = "<operation> /create Create an Application."
  51. Const L_Help_HELP_General12_Text = " /remove Remove an Application."
  52. Const L_Help_HELP_General13_Text = " /unload Unload an Application."
  53. Const L_Help_HELP_General14_Text = " /enable Enable an Application."
  54. Const L_Help_HELP_General15_Text = " /disable Disable an Application."
  55. Const L_Help_HELP_General16_Text = " /getstatus Get the status of an Application."
  56. Const L_Help_HELP_General17_Text = " /restartasp Restart an ASP Application."
  57. Const L_Help_HELP_General18_Text = "<application> Application path. Use either the site name or metabase"
  58. Const L_Help_HELP_General18p1_Text = " path to specify the site. (""Default Web Site"" or w3svc/1)"
  59. Const L_Help_HELP_General22_Text = "For detailed usage:"
  60. Const L_Help_HELP_General23_Text = "IIsApp /create /?"
  61. Const L_Help_HELP_General24_Text = "IIsApp /remove /?"
  62. Const L_Help_HELP_General25_Text = "IIsApp /unload /?"
  63. Const L_Help_HELP_General26_Text = "IIsApp /enable /?"
  64. Const L_Help_HELP_General27_Text = "IIsApp /disable /?"
  65. Const L_Help_HELP_General28_Text = "IIsApp /getstatus /?"
  66. Const L_Help_HELP_General29_Text = "IIsApp /restartasp /?"
  67. ' Create help messages
  68. Const L_Help_HELP_Create01_Text = "Description: quickly create an ""Application"" on a Web Site, Virtual Directory or Directory."
  69. Const L_Help_HELP_Create02_Text = "Syntax: IIsApp [/s <server>] [/u <username>] [/p <password>] /create"
  70. Const L_Help_HELP_Create02p1_Text = " [/a (inproc|outproc|poolproc|<AppPoolID>)] <application>"
  71. Const L_Help_HELP_Create13_Text = "/a Specify the type of application to create."
  72. Const L_Help_HELP_Create13p1_Text = " Backward Compat Mode: inproc|outproc|poolproc"
  73. Const L_Help_HELP_Create13p2_Text = " [Default: poolproc]"
  74. Const L_Help_HELP_Create13p3_Text = " Enhanced Mode: <AppPoolID> assigns the app to an"
  75. Const L_Help_HELP_Create13p4_Text = " application pool. [Default: parent's AppPoolID]"
  76. Const L_Help_HELP_Create21_Text = "IIsApp /import /f c:\config.xml /sp /lm/w3svc/5/Root/401Kapp"
  77. Const L_Help_HELP_Create21p1_Text = " /dp /lm/w3svc/1/Root/401Kapp"
  78. ' Remove help messages
  79. Const L_Help_HELP_Remove01_Text = "Description: quickly remove an ""Application"" on a Web Site, Virtual Directory or Directory."
  80. Const L_Help_HELP_Remove02_Text = "Syntax: IIsApp [/s <server>] [/u <username>] [/p <password>] /remove"
  81. Const L_Help_HELP_Remove02p2_Text = " <application>"
  82. Const L_Help_HELP_Remove13_Text = "/d <DecryptPass> Specifies the password used to encrypt encrypted"
  83. Const L_Help_HELP_Remove13p1_Text = " configuration data. [Default: """"]"
  84. Const L_Help_HELP_Remove14_Text = "/f <File> Configuration file"
  85. Const L_Help_HELP_Remove15_Text = "/sp <SourcePath> The full metabase path to be exported."
  86. Const L_Help_HELP_Remove16_Text = "/inherited Remove inherited settings if set."
  87. Const L_Help_HELP_Remove17_Text = "/children Remove configuration for child nodes."
  88. Const L_Help_HELP_Remove18_Text = "/apped Append configuration to configuration file if it exists."
  89. Const L_Help_HELP_Remove19_Text = "IIsApp /export /f c:\config.xml /sp /lm/w3svc/5/Root/401Kapp"
  90. ''''''''''''''''''''''''
  91. ' Operation codes
  92. Const OPER_CREATE = 1
  93. Const OPER_REMOVE = 2
  94. Const OPER_UNLOAD = 3
  95. Const OPER_ENABLE = 4
  96. Const OPER_DISABLE = 5
  97. Const OPER_GETSTATUS = 6
  98. Const OPER_RESTARTASP = 7
  99. ' Import/Export flags
  100. Const APPCREATE_INPROC = 0
  101. Const APPCREATE_OUTPROC = 1
  102. Const APPCREATE_POOLPROC = 2
  103. '
  104. ' Main block
  105. '
  106. Dim oScriptHelper
  107. Dim strServer, strUser, strPassword, strSite
  108. Dim intOperation, intResult
  109. Dim strAppType
  110. Dim aArgs
  111. ' Default values
  112. strServer = "."
  113. strUser = ""
  114. strPassword = ""
  115. intOperation = 0
  116. strAppType = APPCREATE_POOLPROC
  117. ' Instantiate script helper object
  118. Set oScriptHelper = CreateObject("Microsoft.IIsScriptHelper")
  119. If Err.Number <> 0 Then
  120. WScript.Echo L_ScriptHelper_ErrorMessage
  121. WScript.Echo L_ChkScpHelperReg_ErrorMessage
  122. WScript.Quit(ERR_GENERAL_FAILURE)
  123. End If
  124. Set oScriptHelper.ScriptHost = WScript
  125. ' Check if we are being run with cscript.exe instead of wscript.exe
  126. oScriptHelper.CheckScriptEngine
  127. ' Command Line parsing
  128. Dim argObj, arg
  129. Set argObj = WScript.Arguments
  130. ' Minimum number of parameters must exist
  131. If argObj.Count < 1 Then
  132. WScript.Echo L_NotEnoughParams_ErrorMessage
  133. WScript.Echo L_SeeHelp_Message
  134. WScript.Quit(ERR_GENERAL_FAILURE)
  135. End If
  136. oScriptHelper.ParseCmdLineOptions "server:s:1;user:u:1;password:p:1;[create:c:0;type:a:1];remove::0;unload::0" & _
  137. "enable::0;disable::0;getstatus::0;restartasp::0"
  138. If UBound(oScriptHelper.NamedArguments) < 0 Then
  139. WScript.Echo L_NotEnoughParams_ErrorMessage
  140. WScript.Echo L_SeeHelp_Message
  141. WScript.Quit(ERR_GENERAL_FAILURE)
  142. End If
  143. For Each arg In oScriptHelper.Switches
  144. If IsHelpSwitch(arg) Then
  145. DisplayHelpMessage
  146. WScript.Quit(ERR_OK)
  147. End If
  148. Select Case arg
  149. Case "server"
  150. ' Server information
  151. strServer = oScriptHelper.GetSwitch(arg)
  152. Case "user"
  153. ' User information
  154. strUser = oScriptHelper.GetSwitch(arg)
  155. Case "password"
  156. ' Password information
  157. strPassword = oScriptHelper.GetSwitch(arg)
  158. Case "create"
  159. If (intOperation <> 0) Then
  160. WScript.Echo L_OnlyOneOper_ErrorMessage
  161. WScript.Echo L_SeeHelp_Message
  162. WScript.Quit(ERR_GENERAL_FAILURE)
  163. End If
  164. intOperation = OPER_CREATE
  165. Case "type"
  166. Select Case UCase(oScriptHelper.Switches(arg))
  167. Case "INPROC"
  168. strAppCreate = APPCREATE_INPROC
  169. Case "OUTPROC"
  170. strAppCreate = APPCREATE_OUTPROC
  171. Case "POOLPROC"
  172. strAppCreate = APPCREATE_POOLPROC
  173. Case Else
  174. strAppCreate = oScriptHelper.Switches(arg)
  175. End Select
  176. Case "remove"
  177. If (intOperation <> 0) Then
  178. WScript.Echo L_OnlyOneOper_ErrorMessage
  179. WScript.Echo L_SeeHelp_Message
  180. WScript.Quit(ERR_GENERAL_FAILURE)
  181. End If
  182. intOperation = OPER_REMOVE
  183. Case "unload"
  184. If (intOperation <> 0) Then
  185. WScript.Echo L_OnlyOneOper_ErrorMessage
  186. WScript.Echo L_SeeHelp_Message
  187. WScript.Quit(ERR_GENERAL_FAILURE)
  188. End If
  189. intOperation = OPER_UNLOAD
  190. Case "enable"
  191. If (intOperation <> 0) Then
  192. WScript.Echo L_OnlyOneOper_ErrorMessage
  193. WScript.Echo L_SeeHelp_Message
  194. WScript.Quit(ERR_GENERAL_FAILURE)
  195. End If
  196. intOperation = OPER_ENABLE
  197. Case "disable"
  198. If (intOperation <> 0) Then
  199. WScript.Echo L_OnlyOneOper_ErrorMessage
  200. WScript.Echo L_SeeHelp_Message
  201. WScript.Quit(ERR_GENERAL_FAILURE)
  202. End If
  203. intOperation = OPER_DISABLE
  204. Case "getstatus"
  205. If (intOperation <> 0) Then
  206. WScript.Echo L_OnlyOneOper_ErrorMessage
  207. WScript.Echo L_SeeHelp_Message
  208. WScript.Quit(ERR_GENERAL_FAILURE)
  209. End If
  210. intOperation = OPER_GETSTATUS
  211. Case "restartasp"
  212. If (intOperation <> 0) Then
  213. WScript.Echo L_OnlyOneOper_ErrorMessage
  214. WScript.Echo L_SeeHelp_Message
  215. WScript.Quit(ERR_GENERAL_FAILURE)
  216. End If
  217. intOperation = OPER_RESTARTASP
  218. End Select
  219. Next
  220. ' Check Parameters
  221. If (intOperation = 0) Then
  222. DisplayHelpMessage
  223. WScript.Quit(ERR_GENERAL_FAILURE)
  224. End If
  225. ' Initializes authentication with remote machine
  226. intResult = oScriptHelper.InitAuthentication(strServer, strUser, strPassword)
  227. If intResult <> 0 Then
  228. WScript.Quit(intResult)
  229. End If
  230. ' Choose operation
  231. Select Case intOperation
  232. Case OPER_CREATE
  233. intResult = Create(strAppCreate)
  234. Case OPER_REMOVE
  235. intResult = Remove()
  236. Case OPER_UNLOAD
  237. intResult = Unload()
  238. Case OPER_ENABLE
  239. intResult = Enable()
  240. Case OPER_DISABLE
  241. intResult = Disable()
  242. Case OPER_GETSTATUS
  243. intResult = GetStatus()
  244. Case OPER_RESTARTASP
  245. intResult = RestartASP()
  246. End Select
  247. ' Return value to command processor
  248. WScript.Quit(intResult)
  249. '''''''''''''''''''''''''
  250. ' End Of Main Block
  251. '''''''''''''''''''''
  252. '''''''''''''''''''''''''''
  253. ' DisplayHelpMessage
  254. '''''''''''''''''''''''''''
  255. Sub DisplayHelpMessage()
  256. WScript.Echo L_Help_HELP_General01_Text
  257. WScript.Echo L_Empty_Text
  258. WScript.Echo L_Help_HELP_General02_Text
  259. WScript.Echo L_Help_HELP_General03_Text
  260. WScript.Echo L_Empty_Text
  261. WScript.Echo L_Help_HELP_General04_Text
  262. WScript.Echo L_Help_HELP_General05_Text
  263. WScript.Echo L_Help_HELP_General06_Text
  264. WScript.Echo L_Help_HELP_General07_Text
  265. WScript.Echo L_Help_HELP_General08_Text
  266. WScript.Echo L_Help_HELP_General09_Text
  267. WScript.Echo L_Help_HELP_General10_Text
  268. WScript.Echo L_Help_HELP_General11_Text
  269. WScript.Echo L_Help_HELP_General12_Text
  270. WScript.Echo L_Empty_Text
  271. WScript.Echo L_Help_HELP_General22_Text
  272. WScript.Echo L_Empty_Text
  273. WScript.Echo L_Help_HELP_General23_Text
  274. WScript.Echo L_Help_HELP_General24_Text
  275. End Sub
  276. Sub DisplayCreateHelpMessage()
  277. WScript.Echo L_Help_HELP_Create01_Text
  278. WScript.Echo L_Help_HELP_Create01p1_Text
  279. WScript.Echo L_Empty_Text
  280. WScript.Echo L_Help_HELP_Create02_Text
  281. WScript.Echo L_Empty_Text
  282. WScript.Echo L_Help_HELP_Status03_Text
  283. WScript.Echo L_Empty_Text
  284. WScript.Echo L_Help_HELP_General06_Text
  285. WScript.Echo L_Help_HELP_General07_Text
  286. WScript.Echo L_Help_HELP_General08_Text
  287. WScript.Echo L_Help_HELP_General09_Text
  288. WScript.Echo L_Help_HELP_General10_Text
  289. WScript.Echo L_Help_HELP_Status09_Text
  290. WScript.Echo L_Help_HELP_Status09p1_Text
  291. WScript.Echo L_Empty_Text
  292. WScript.Echo L_Empty_Text
  293. WScript.Echo L_Help_HELP_Status10_Text
  294. WScript.Echo L_Empty_Text
  295. WScript.Echo L_Help_HELP_Create11_Text
  296. WScript.Echo L_Help_HELP_Create12_Text
  297. WScript.Echo L_Help_HELP_Create13_Text
  298. End Sub
  299. Sub DisplayRemoveHelpMessage()
  300. WScript.Echo L_Help_HELP_Remove01_Text
  301. WScript.Echo L_Empty_Text
  302. WScript.Echo L_Help_HELP_Remove02_Text
  303. WScript.Echo L_Empty_Text
  304. WScript.Echo L_Help_HELP_General06_Text
  305. WScript.Echo L_Help_HELP_General07_Text
  306. WScript.Echo L_Help_HELP_General08_Text
  307. WScript.Echo L_Help_HELP_General09_Text
  308. WScript.Echo L_Help_HELP_General10_Text
  309. WScript.Echo L_Empty_Text
  310. WScript.Echo L_Help_HELP_Remove11_Text
  311. WScript.Echo L_Help_HELP_Remove12_Text
  312. WScript.Echo L_Help_HELP_Remove13_Text
  313. WScript.Echo L_Help_HELP_Remove14_Text
  314. WScript.Echo L_Help_HELP_Remove15_Text
  315. End Sub
  316. '''''''''''''''''''''''''''
  317. ' Create Function
  318. '''''''''''''''''''''''''''
  319. Function Create(strAppCreate)
  320. On Error Resume Next
  321. Dim Site
  322. Dim aSites
  323. Dim ComputerObj
  324. ' Normalize path names (get all metabase paths)
  325. aSites = oScriptHelper.FindWebSite(oScriptHelper.NamedArguments)
  326. For Each Site In aSites
  327. Next
  328. Set ComputerObj = oScriptHelper.ProviderObj.get("IIsComputer='LM'")
  329. If Err Then
  330. WScript.Echo L_GetComputerObj_ErrorMessage
  331. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  332. WScript.Quit(Err.Number)
  333. End If
  334. ' Call Import method from the computer object
  335. ComputerObj.Import strPassword, strFile, strSourcePath, strDestPath, intFlags, strLogFile
  336. If Err Then
  337. WScript.Echo L_Import_ErrorMessage
  338. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  339. WScript.Quit(Err.Number)
  340. End If
  341. WScript.Echo L_Path_Text & " " & strSourcePath & " " & L_HasBeen_Message & " " & L_Imported_Text
  342. End Function
  343. '''''''''''''''''''''''''''
  344. ' Remove Function
  345. '''''''''''''''''''''''''''
  346. Function Remove()
  347. On Error Resume Next
  348. Dim ComputerObj
  349. Set ComputerObj = oScriptHelper.ProviderObj.get("IIsComputer='LM'")
  350. If Err Then
  351. WScript.Echo L_GetComputerObj_ErrorMessage
  352. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  353. WScript.Quit(Err.Number)
  354. End If
  355. ' Call Import method from the computer object
  356. ComputerObj.Export strPassword, strFile, strSourcePath, intFlags
  357. If Err Then
  358. WScript.Echo L_Export_ErrorMessage
  359. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  360. WScript.Quit(Err.Number)
  361. End If
  362. WScript.Echo L_Path_Text & " " & strSourcePath & " " & L_HasBeen_Message & " " & L_Exported_Text
  363. End Function
  364. '''''''''''''''''''''''''''
  365. ' Helper Functions
  366. '''''''''''''''''''''''''''
  367. '''''''''''''''''''''''''''
  368. ' IsHelpSwitch
  369. '
  370. ' Returns true if the specified
  371. ' parameter is a help switch
  372. ' (ie.: /?, /h, /H, /help, /HELP, etc)
  373. '''''''''''''''''''''''''''
  374. Function IsHelpSwitch(param)
  375. Dim result
  376. result = False
  377. If Left(param, 1) = "/" or Left(param, 1) = "-" Then
  378. Select Case UCase(Right(param, Len(param) - 1))
  379. Case "?"
  380. result = True
  381. Case "H"
  382. result = True
  383. Case "HELP"
  384. result = True
  385. Case Else
  386. result = False
  387. End Select
  388. End If
  389. IsHelpSwitch = result
  390. End Function