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.

809 lines
29 KiB

  1. '
  2. ' Copyright (c) Microsoft Corporation. All rights reserved.
  3. '
  4. ' VBScript Source File
  5. '
  6. ' Script Name: IIsVDir.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_WebDir_Message = "Web directory"
  16. Const L_HasBeenDeleted_Message = "has been DELETED"
  17. Const L_InvalidPath_ErrorMessage = "Invalid site path."
  18. Const L_VPath_Message = "Virtual Path"
  19. Const L_Root_Message = "ROOT"
  20. Const L_MetabasePath_Message = "Metabase Path"
  21. Const L_AliasName_Text = "Alias"
  22. Const L_Path_Text = "Physical Root"
  23. Const L_Error_ErrorMessage = "Error"
  24. Const L_AppRecursiveDel_ErrorMessage = "Could not recursively delete application from web directory."
  25. Const L_VDirDel_ErrorMessage = "Could not delete web directory."
  26. Const L_CannotCreateDir_ErrorMessage = "Could not create root directory."
  27. Const L_DirFormat_ErrorMessage = "Root directory format unknown. Please use the '<drive>:\<path>' format."
  28. Const L_AppCreate_ErrorMessage = "Error trying to create pooled-proc application on new web directory."
  29. Const L_OperationRequired_ErrorMessage = "Please specify an operation before the arguments."
  30. Const L_NotEnoughParam_ErrorMessage = "Not enough parameters."
  31. Const L_Query_ErrorMessage = "Error occurred while querying WMI provider."
  32. Const L_VDirExists1_ErrorMessage = "Virtual directory"
  33. Const L_VDirExists2_ErrorMessage = "already exists."
  34. Const L_VDirDoesntExist_ErrorMessage = "Virtual directory doesn't exist"
  35. Const L_OnlyOneOper_ErrorMessage = "Please specify only one operation at a time."
  36. Const L_ScriptHelper_ErrorMessage = "Could not create an instance of the IIsScriptHelper object."
  37. Const L_ChkScpHelperReg_ErrorMessage = "Please register the Microsoft.IIsScriptHelper component."
  38. Const L_CmdLib_ErrorMessage = "Unable to create instance of the CmdLib object."
  39. Const L_VDirsNotFound_ErrorMessage = "No virtual sub-directories available."
  40. Const L_SiteNotFound_ErrorMessage = "Could not find website"
  41. Const L_PassWithoutUser_ErrorMessage = "Please specify /u switch before using /p."
  42. Const L_WMIConnect_ErrorMessage = "Could not connect to WMI provider."
  43. Const L_MapDrive_ErrorMessage = "Could not map network drive."
  44. Const L_GetSetting_ErrorMessage = "Unable to get Setting class from IIS namespace."
  45. Const L_CannotDelRoot_ErrorMessage = "Cannot delete the ROOT virtual directory. Please specify another one."
  46. Const L_WrongVDirPath_ErrorMessage = "Parent virtual directory points to an unexistant file system path."
  47. Const L_CannotBuildNameSpace_ErrorMessage = "Could not build metabase namespace for the new virtual directory."
  48. Const L_KeyIsntVDir_ErrorMessage = "Specified metabase path is not a virtual directory."
  49. Const L_CannotGetVDir_ErrorMessage = "Could not get virtual directory object."
  50. Const L_InvalidAlias_ErrorMessage = "Alias contains invalid character(s)."
  51. Const L_NotEnoughParams_ErrorMessage = "Not enough parameters."
  52. Const L_InvalidSwitch_ErrorMessage = "Invalid switch: "
  53. '''''''''''''''''''''
  54. ' Help
  55. ' General help messages
  56. Const L_SeeHelp_Message = "Type IIsVDir /? for help."
  57. Const L_SeeCreateHelp_Message = "Type IIsVDir /create /? for help."
  58. Const L_SeeDeleteHelp_Message = "Type IIsVDir /delete /? for help."
  59. Const L_SeeQueryHelp_Message = "Type IIsVDir /query /? for help."
  60. Const L_Help_HELP_General01_Text = "Description: Create, delete, or query a web directory"
  61. Const L_Help_HELP_General02_Text = "Syntax: IIsVDir [/s <server> [/u <username> [/p <password>]]] /<operation>"
  62. Const L_Help_HELP_General03_Text = " [arguments]"
  63. Const L_Help_HELP_General04_Text = "Parameters:"
  64. Const L_Help_HELP_General06_Text = "Value Description"
  65. Const L_Help_HELP_General07_Text = "/s <server> Connect to machine <server> [Default: this system]"
  66. Const L_Help_HELP_General08_Text = "/u <username> Connect as <username> or <domain>\<username>"
  67. Const L_Help_HELP_General09_Text = " [Default: current user]"
  68. Const L_Help_HELP_General10_Text = "/p <password> Password for the <username> user"
  69. Const L_Help_HELP_General11_Text = "<operation> /create Creates a web virtual directory on a"
  70. Const L_Help_HELP_General12_Text = " specified web site."
  71. Const L_Help_HELP_General13_Text = " /delete Deletes a web virtual directory from a"
  72. Const L_Help_HELP_General14_Text = " specified web site."
  73. Const L_Help_HELP_General15_Text = " /query Lists all virtual directories under"
  74. Const L_Help_HELP_General16_Text = " the specified path."
  75. Const L_Help_HELP_General17_Text = "For detailed usage:"
  76. Const L_Help_HELP_General18_Text = "IIsVDir /create /?"
  77. Const L_Help_HELP_General19_Text = "IIsVDir /delete /?"
  78. Const L_Help_HELP_General20_Text = "IIsVDir /query /?"
  79. ' Common to all status change commands
  80. Const L_Help_HELP_Common03_Text = "Parameters:"
  81. Const L_Help_HELP_Common09_Text = "<website> Use either the site name or metabase path to specify"
  82. Const L_Help_HELP_Common09p1_Text = " the site. (""Default Web Site"" or w3svc/1)"
  83. Const L_Help_HELP_Common10_Text = "<path> Virtual path for the new virtual directory's parent."
  84. Const L_Help_HELP_Common10p1_Text = " This virtual path must already exist."
  85. Const L_Help_HELP_Common11_Text = "Examples:"
  86. ' Delete help messages
  87. Const L_Help_HELP_Delete01_Text = "Description: Deletes a web virtual directory from a specified web site."
  88. Const L_Help_HELP_Delete02_Text = "Syntax: IIsVDir [/s <server> [/u <username> [/p <password>]]] /delete"
  89. Const L_Help_HELP_Delete02p1_Text = " <website>[/path]<alias>"
  90. Const L_Help_HELP_Delete11_Text = "IIsVDir /delete ""My Site""/Mydir"
  91. Const L_Help_HELP_Delete12_Text = "IIsVDir /delete w3svc/1/ROOT/Users/Public/Mydir"
  92. Const L_Help_HELP_Delete13_Text = "IIsVDir /s Server1 /u Administrator /p p@ssWOrd /delete ""My Site""/Mydir"
  93. ' Query help messages
  94. Const L_Help_HELP_Query01_Text = "Description: Lists all virtual directories under a given path."
  95. Const L_Help_HELP_Query02_Text = "Syntax: IIsVDir [/s <server> [/u <username> [/p <password>]]] /query"
  96. Const L_Help_HELP_Query02p1_Text = " <website>[/path]"
  97. Const L_Help_HELP_Query11_Text = "IIsVDir /query ""My Site"""
  98. Const L_Help_HELP_Query12_Text = "IIsVDir /query w3svc/1/ROOT"
  99. Const L_Help_HELP_Query13_Text = "IIsVDir /query ""My Site""/Users/Public"
  100. Const L_Help_HELP_Query14_Text = "IIsVDir /s Server1 /u Administrator /p p@ssWOrd /query ""My Site""/Users"
  101. ' Create help messages
  102. Const L_Help_HELP_Create01_Text = "Description: Creates a web virtual directory on a specified web site."
  103. Const L_Help_HELP_Create02_Text = "Syntax: IIsVDir [/s <server> [/u <username> [/p <password>]]] /create"
  104. Const L_Help_HELP_Create02p1_Text = " <website>[/path] <alias> <root>"
  105. Const L_Help_HELP_Create11_Text = "<alias> The name of the virtual directory"
  106. Const L_Help_HELP_Create12_Text = "<root> Physical path of the virtual directory. If the"
  107. Const L_Help_HELP_Create12p1_Text = " physical path does not exist, it will be created."
  108. Const L_Help_HELP_Create15_Text = "IIsVDir /create ""My Site"" Mydir c:\mydir"
  109. Const L_Help_HELP_Create16_Text = "IIsVDir /create w3svc/1/ROOT MyDir c:\mydir"
  110. Const L_Help_HELP_Create17_Text = "IIsVDir /create ""My Site""/Users/Public Mydir c:\mydir"
  111. Const L_Help_HELP_Create18_Text = "IIsVDir /s Server1 /u Administrator /p p@assWOrd /create ""My Site"" Mydir"
  112. Const L_Help_HELP_Create19_Text = " c:\mydir"
  113. ''''''''''''''''''''''''
  114. ' Operation codes
  115. Const OPER_DELETE = 1
  116. Const OPER_CREATE = 2
  117. Const OPER_QUERY = 3
  118. '
  119. ' Main block
  120. '
  121. Dim oScriptHelper, oCmdLib
  122. Dim strServer, strUser, strPassword, strSite
  123. Dim strPath, strVPath, strAlias, strRoot
  124. Dim intOperation, intResult
  125. Dim aArgs, arg
  126. Dim strCmdLineOptions
  127. Dim oError
  128. ' Default values
  129. strServer = "."
  130. strUser = ""
  131. strPassword = ""
  132. intOperation = 0
  133. strSite = ""
  134. strPath = ""
  135. ' Instantiate script helper object
  136. Set oScriptHelper = CreateObject("Microsoft.IIsScriptHelper")
  137. If Err.Number <> 0 Then
  138. WScript.Echo L_ScriptHelper_ErrorMessage
  139. WScript.Echo L_ChkScpHelperReg_ErrorMessage
  140. WScript.Quit(ERR_GENERAL_FAILURE)
  141. End If
  142. Set oScriptHelper.ScriptHost = WScript
  143. ' Check if we are being run with cscript.exe instead of wscript.exe
  144. oScriptHelper.CheckScriptEngine
  145. ' Minimum number of parameters must exist
  146. If WScript.Arguments.Count < 1 Then
  147. WScript.Echo L_NotEnoughParam_ErrorMessage
  148. WScript.Echo L_SeeHelp_Message
  149. WScript.Quit(ERR_GENERAL_FAILURE)
  150. End If
  151. strCmdLineOptions = "[server:s:1;user:u:1;password:p:1];delete:d:1;create:c:3;query:q:1"
  152. Set oError = oScriptHelper.ParseCmdLineOptions(strCmdLineOptions)
  153. If Not oError Is Nothing Then
  154. If oError.ErrorCode = oScriptHelper.ERROR_NOT_ENOUGH_ARGS Then
  155. ' Not enough arguments for a specified switch
  156. WScript.Echo L_NotEnoughParams_ErrorMessage
  157. Select Case LCase(oError.SwitchName)
  158. Case "create"
  159. WScript.Echo L_SeeCreateHelp_Message
  160. Case "delete"
  161. WScript.Echo L_SeeDeleteHelp_Message
  162. Case "query"
  163. WScript.Echo L_SeeQueryHelp_Message
  164. Case Else
  165. WScript.Echo L_SeeHelp_Message
  166. End Select
  167. Else
  168. ' Invalid switch
  169. WScript.Echo L_InvalidSwitch_ErrorMessage & oError.SwitchName
  170. WScript.Echo L_SeeHelp_Message
  171. End If
  172. WScript.Quit(ERR_GENERAL_FAILURE)
  173. End If
  174. If oScriptHelper.GlobalHelpRequested Then
  175. DisplayHelpMessage
  176. WScript.Quit(ERR_OK)
  177. End If
  178. For Each arg In oScriptHelper.Switches
  179. Select Case arg
  180. Case "server"
  181. ' Server information
  182. strServer = oScriptHelper.GetSwitch(arg)
  183. Case "user"
  184. ' User information
  185. strUser = oScriptHelper.GetSwitch(arg)
  186. Case "password"
  187. ' Password information
  188. strPassword = oScriptHelper.GetSwitch(arg)
  189. Case "create"
  190. If (intOperation <> 0) Then
  191. WScript.Echo L_OnlyOneOper_ErrorMessage
  192. WScript.Echo L_SeeHelp_Message
  193. WScript.Quit(ERR_GENERAL_FAILURE)
  194. End If
  195. intOperation = OPER_CREATE
  196. If oScriptHelper.IsHelpRequested(arg) Then
  197. DisplayCreateHelpMessage
  198. WScript.Quit(ERR_OK)
  199. End If
  200. aArgs = oScriptHelper.GetSwitch(arg)
  201. strVPath = aArgs(0)
  202. strAlias = aArgs(1)
  203. strRoot = aArgs(2)
  204. Case "delete"
  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_DELETE
  211. If oScriptHelper.IsHelpRequested(arg) Then
  212. DisplayDeleteHelpMessage
  213. WScript.Quit(ERR_OK)
  214. End If
  215. strPath = oScriptHelper.GetSwitch(arg)
  216. Case "query"
  217. If (intOperation <> 0) Then
  218. WScript.Echo L_OnlyOneOper_ErrorMessage
  219. WScript.Echo L_SeeHelp_Message
  220. WScript.Quit(ERR_GENERAL_FAILURE)
  221. End If
  222. intOperation = OPER_QUERY
  223. If oScriptHelper.IsHelpRequested(arg) Then
  224. DisplayQueryHelpMessage
  225. WScript.Quit(ERR_OK)
  226. End If
  227. strPath = oScriptHelper.GetSwitch(arg)
  228. ' strVPath = aArgs(0)
  229. ' strAlias = aArgs(1)
  230. ' strRoot = aArgs(2)
  231. End Select
  232. Next
  233. ' Check Parameters
  234. If (intOperation = 0) Then
  235. WScript.Echo L_OperationRequired_ErrorMessage
  236. WScript.Echo L_SeeHelp_Message
  237. WScript.Quit(ERR_GENERAL_FAILURE)
  238. End If
  239. ' Check if /p is specified but /u isn't. In this case, we should bail out with an error
  240. If oScriptHelper.Switches.Exists("password") And Not oScriptHelper.Switches.Exists("user") Then
  241. WScript.Echo L_PassWithoutUser_ErrorMessage
  242. WScript.Quit(ERR_GENERAL_FAILURE)
  243. End If
  244. ' Check if /u is specified but /p isn't. In this case, we should ask for a password
  245. If oScriptHelper.Switches.Exists("user") And Not oScriptHelper.Switches.Exists("password") Then
  246. Set oCmdLib = CreateObject("Microsoft.CmdLib")
  247. Set oCmdLib.ScriptingHost = WScript.Application
  248. If Err.Number Then
  249. WScript.Echo L_CmdLib_ErrorMessage
  250. WScript.Quit(Err.Number)
  251. Else
  252. strPassword = oCmdLib.GetPassword
  253. Set oCmdLib = Nothing
  254. End If
  255. End If
  256. ' Initializes authentication with remote machine
  257. intResult = oScriptHelper.InitAuthentication(strServer, strUser, strPassword)
  258. If intResult <> 0 Then
  259. WScript.Quit(intResult)
  260. End If
  261. ' Choose operation
  262. Select Case intOperation
  263. Case OPER_CREATE
  264. intResult = CreateWebVDir(strVPath, strAlias, strRoot)
  265. Case OPER_DELETE
  266. intResult = DeleteWebVDir(strPath)
  267. Case OPER_QUERY
  268. intResult = QueryWebVDir(strPath)
  269. End Select
  270. ' Return value to command processor
  271. WScript.Quit(intResult)
  272. '''''''''''''''''''''''''
  273. ' End Of Main Block
  274. '''''''''''''''''''''
  275. '''''''''''''''''''''''''''
  276. ' ParseSitePath
  277. '''''''''''''''''''''''''''
  278. Function ParseSitePath(strSitePath)
  279. Dim iFirstSlash, iSecondSlash, iIndex
  280. Dim strSite, strPath
  281. Dim aPath, aWebSites
  282. On Error Resume Next
  283. ' Replace any existing back-slashes with forward-slashes
  284. strSitePath = Replace(strSitePath, "\", "/")
  285. aPath = Split(strSitePath, "/", -1)
  286. ' Fills strPath
  287. If (UCase(aPath(0)) = "W3SVC") Then
  288. ' First argument is a metabase path
  289. If (UBound(aPath) < 1) Then
  290. WScript.Echo L_InvalidPath_ErrorMessage
  291. WScript.Quit(ERR_GENERAL_FAILURE)
  292. End If
  293. ' Second array element must be a number (site ID)
  294. If Not IsNumeric(aPath(1)) Then
  295. WScript.Echo L_InvalidPath_ErrorMessage
  296. WScript.Quit(ERR_GENERAL_FAILURE)
  297. End If
  298. ' Second element of aPath should be the site number so ...
  299. strPath = "W3SVC/" & aPath(1)
  300. ' Call FindWebSite to make sure web site exists
  301. aWebSites = oScriptHelper.FindSite("Web", Array(strPath))
  302. If IsArray(aWebSites) Then
  303. If UBound(aWebSites) = -1 Then
  304. WScript.Echo L_SiteNotFound_ErrorMessage & " """ & strPath & """."
  305. ParseSitePath = Empty
  306. Exit Function
  307. End If
  308. End If
  309. strPath = strPath & "/ROOT"
  310. ' Check for ROOT string and grab the rest for strPath
  311. iIndex = 1
  312. If (UBound(aPath) > 1) Then
  313. If (UCase(aPath(2)) = "ROOT") Then
  314. iIndex = 2
  315. End If
  316. End If
  317. Else
  318. ' First argument is a site name (server comment property)
  319. ' Call FindWebSite to resolve site name to metabase path
  320. aWebSites = oScriptHelper.FindSite("Web", Array(aPath(0)))
  321. If IsArray(aWebSites) Then
  322. If UBound(aWebSites) = -1 Then
  323. WScript.Echo L_SiteNotFound_ErrorMessage & " """ & aPath(0) & """."
  324. ParseSitePath = Empty
  325. Exit Function
  326. Else
  327. strPath = aWebSites(0)
  328. End If
  329. Else
  330. ' Got duplicate sites. We should quit.
  331. ParseSitePath = Empty
  332. Exit Function
  333. End If
  334. strPath = strPath & "/ROOT"
  335. iIndex = 0
  336. End If
  337. ' Build strPath
  338. iIndex = iIndex + 1
  339. Do While iIndex <= UBound(aPath)
  340. If (aPath(iIndex) = "") Then
  341. Exit Do
  342. End If
  343. strPath = strPath & "/" & aPath(iIndex)
  344. iIndex = iIndex + 1
  345. Loop
  346. ParseSitePath = strPath
  347. End Function
  348. '''''''''''''''''''''''''''
  349. ' DisplayHelpMessage
  350. '''''''''''''''''''''''''''
  351. Sub DisplayHelpMessage()
  352. WScript.Echo L_Help_HELP_General01_Text
  353. WScript.Echo
  354. WScript.Echo L_Help_HELP_General02_Text
  355. WScript.Echo L_Help_HELP_General03_Text
  356. WScript.Echo
  357. WScript.Echo L_Help_HELP_General04_Text
  358. WScript.Echo
  359. WScript.Echo L_Help_HELP_General06_Text
  360. WScript.Echo L_Help_HELP_General07_Text
  361. WScript.Echo L_Help_HELP_General08_Text
  362. WScript.Echo L_Help_HELP_General09_Text
  363. WScript.Echo L_Help_HELP_General10_Text
  364. WScript.Echo L_Help_HELP_General11_Text
  365. WScript.Echo L_Help_HELP_General12_Text
  366. WScript.Echo L_Help_HELP_General13_Text
  367. WScript.Echo L_Help_HELP_General14_Text
  368. WScript.Echo L_Help_HELP_General15_Text
  369. WScript.Echo L_Help_HELP_General16_Text
  370. WScript.Echo
  371. WScript.Echo L_Help_HELP_General17_Text
  372. WScript.Echo
  373. WScript.Echo L_Help_HELP_General18_Text
  374. WScript.Echo L_Help_HELP_General19_Text
  375. WScript.Echo L_Help_HELP_General20_Text
  376. End Sub
  377. Sub DisplayDeleteHelpMessage()
  378. WScript.Echo L_Help_HELP_Delete01_Text
  379. WScript.Echo
  380. WScript.Echo L_Help_HELP_Delete02_Text
  381. WScript.Echo L_Help_HELP_Delete02p1_Text
  382. WScript.Echo
  383. WScript.Echo L_Help_HELP_Common03_Text
  384. WScript.Echo
  385. WScript.Echo L_Help_HELP_General06_Text
  386. WScript.Echo L_Help_HELP_General07_Text
  387. WScript.Echo L_Help_HELP_General08_Text
  388. WScript.Echo L_Help_HELP_General09_Text
  389. WScript.Echo L_Help_HELP_General10_Text
  390. WScript.Echo L_Help_HELP_Common09_Text
  391. WScript.Echo L_Help_HELP_Common09p1_Text
  392. WScript.Echo L_Help_HELP_Common10_Text
  393. WScript.Echo
  394. WScript.Echo L_Help_HELP_Common11_Text
  395. WScript.Echo
  396. WScript.Echo L_Help_HELP_Delete11_Text
  397. WScript.Echo L_Help_HELP_Delete12_Text
  398. WScript.Echo L_Help_HELP_Delete13_Text
  399. End Sub
  400. Sub DisplayCreateHelpMessage()
  401. WScript.Echo L_Help_HELP_Create01_Text
  402. WScript.Echo
  403. WScript.Echo L_Help_HELP_Create02_Text
  404. WScript.Echo L_Help_HELP_Create02p1_Text
  405. WScript.Echo
  406. WScript.Echo L_Help_HELP_Common03_Text
  407. WScript.Echo
  408. WScript.Echo L_Help_HELP_General06_Text
  409. WScript.Echo L_Help_HELP_General07_Text
  410. WScript.Echo L_Help_HELP_General08_Text
  411. WScript.Echo L_Help_HELP_General09_Text
  412. WScript.Echo L_Help_HELP_General10_Text
  413. WScript.Echo L_Help_HELP_Common09_Text
  414. WScript.Echo L_Help_HELP_Common09p1_Text
  415. WScript.Echo L_Help_HELP_Common10_Text
  416. WScript.Echo L_Help_HELP_Common10p1_Text
  417. WScript.Echo L_Help_HELP_Create11_Text
  418. WScript.Echo L_Help_HELP_Create12_Text
  419. WScript.Echo L_Help_HELP_Create12p1_Text
  420. WScript.Echo
  421. WScript.Echo L_Help_HELP_Common11_Text
  422. WScript.Echo
  423. WScript.Echo L_Help_HELP_Create15_Text
  424. WScript.Echo L_Help_HELP_Create16_Text
  425. WScript.Echo L_Help_HELP_Create17_Text
  426. WScript.Echo L_Help_HELP_Create18_Text
  427. WScript.Echo L_Help_HELP_Create19_Text
  428. End Sub
  429. Sub DisplayQueryHelpMessage()
  430. WScript.Echo L_Help_HELP_Query01_Text
  431. WScript.Echo
  432. WScript.Echo L_Help_HELP_Query02_Text
  433. WScript.Echo L_Help_HELP_Query02p1_Text
  434. WScript.Echo
  435. WScript.Echo L_Help_HELP_Common03_Text
  436. WScript.Echo
  437. WScript.Echo L_Help_HELP_General06_Text
  438. WScript.Echo L_Help_HELP_General07_Text
  439. WScript.Echo L_Help_HELP_General08_Text
  440. WScript.Echo L_Help_HELP_General09_Text
  441. WScript.Echo L_Help_HELP_General10_Text
  442. WScript.Echo L_Help_HELP_Common09_Text
  443. WScript.Echo L_Help_HELP_Common09p1_Text
  444. WScript.Echo L_Help_HELP_Common10_Text
  445. WScript.Echo L_Help_HELP_Common10p1_Text
  446. WScript.Echo
  447. WScript.Echo L_Help_HELP_Common11_Text
  448. WScript.Echo
  449. WScript.Echo L_Help_HELP_Query11_Text
  450. WScript.Echo L_Help_HELP_Query12_Text
  451. WScript.Echo L_Help_HELP_Query13_Text
  452. WScript.Echo L_Help_HELP_Query14_Text
  453. End Sub
  454. '''''''''''''''''''''''''''
  455. ' DeleteWebVDir
  456. '''''''''''''''''''''''''''
  457. Function DeleteWebVDir(strVPath)
  458. Dim strPath
  459. Dim rootVDirObj, providerObj
  460. On Error Resume Next
  461. oScriptHelper.WMIConnect
  462. If Err.Number Then
  463. WScript.Echo L_WMIConnect_ErrorMessage
  464. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  465. ChangeWebSiteStatus = Err.Number
  466. Exit Function
  467. End If
  468. Set providerObj = oScriptHelper.ProviderObj
  469. strPath = ParseSitePath(strVPath)
  470. If IsEmpty(strPath) Then
  471. ' Got problems parsing the path
  472. WScript.Echo L_SeeDeleteHelp_Message
  473. DeleteWebVDir = ERR_GENERAL_FAILURE
  474. Exit Function
  475. End If
  476. ' Don't delete ROOT Vdir
  477. If UCase(Right(strPath, 4)) = "ROOT" Then
  478. WScript.Echo L_CannotDelRoot_ErrorMessage
  479. DeleteWebVDir = ERR_GENERAL_FAILURE
  480. Exit Function
  481. End If
  482. ' Check vdir existance
  483. Set rootVDirObj = providerObj.Get("IIsWebVirtualDir='" & strPath & "'")
  484. If Err.Number Then
  485. Select Case Err.Number
  486. Case &H80041002
  487. WScript.Echo L_VDirDoesntExist_ErrorMessage & " (" & strVPath & ")"
  488. Case &H8004103A
  489. WScript.Echo L_KeyIsntVDir_ErrorMessage
  490. Case Else
  491. WScript.Echo L_CannotGetVDir_ErrorMessage
  492. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  493. End Select
  494. DeleteWebVDir = Err.Number
  495. Exit Function
  496. End If
  497. ' First delete application recursively in this vdir
  498. rootVDirObj.AppDelete(True)
  499. If Err.Number Then
  500. WScript.Echo L_AppRecursiveDel_ErrorMessage
  501. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  502. DeleteWebVDir = Err.Number
  503. Exit Function
  504. End If
  505. rootVDirObj.Delete_()
  506. If Err.Number Then
  507. WScript.Echo L_VDirDel_ErrorMessage
  508. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  509. DeleteWebVDir = Err.Number
  510. Exit Function
  511. End If
  512. WScript.Echo L_WebDir_Message & " " & strVPath & " " & L_HasBeenDeleted_Message & "."
  513. DeleteWebVDir = ERR_OK
  514. End Function
  515. '''''''''''''''''''''''''''
  516. ' CreateWebVDir
  517. '''''''''''''''''''''''''''
  518. Function CreateWebVDir(strVPath, strAlias, strRoot)
  519. Dim strPath, strStatus, strNewVdir, strRootVDir
  520. Dim vdirClassObj, serverObj, vdirObj, providerObj
  521. Dim intResult
  522. Const APP_POOLED = 2
  523. On Error Resume Next
  524. ' Parse Alias for correctness
  525. If InStr(strAlias, "/") <> 0 Or InStr(strAlias, "\") <> 0 Then
  526. WScript.Echo L_InvalidAlias_ErrorMessage
  527. WScript.Echo L_SeeCreateHelp_Message
  528. CreateWebVDir = ERR_GENERAL_FAILURE
  529. Exit Function
  530. End If
  531. oScriptHelper.WMIConnect
  532. If Err.Number Then
  533. WScript.Echo L_WMIConnect_ErrorMessage
  534. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  535. CreateWebVDir = Err.Number
  536. Exit Function
  537. End If
  538. Set providerObj = oScriptHelper.ProviderObj
  539. ' Extract options from array to the correspondent variables
  540. strPath = ParseSitePath(strVPath)
  541. If IsEmpty(strPath) Then
  542. ' Got problems parsing the path
  543. WScript.Echo L_SeeCreateHelp_Message
  544. CreateWebVDir = ERR_GENERAL_FAILURE
  545. Exit Function
  546. End If
  547. ' Build new vdir name
  548. strNewVdir = strPath & "/" & strAlias
  549. ' Check if vdir already exists
  550. Set vdirObj = providerObj.Get("IIsWebVirtualDirSetting='" & strNewVdir & "'")
  551. If Err.Number = 0 Then
  552. WScript.Echo L_VDirExists1_ErrorMessage & " '" & strNewVdir & "' " & L_VDirExists2_ErrorMessage
  553. CreateWebVDir = ERR_GENERAL_FAILURE
  554. Exit Function
  555. End If
  556. Err.Clear
  557. ' Create physical directory
  558. oScriptHelper.CreateFSDir strRoot
  559. If Err.Number Then
  560. Select Case Err.Number
  561. Case &H8007000C
  562. WScript.Echo L_DirFormat_ErrorMessage
  563. WScript.Echo L_SeeCreateHelp_Message
  564. Case &H8007000F
  565. WScript.Echo L_MapDrive_ErrorMessage
  566. Case Else
  567. WScript.Echo L_CannotCreateDir_ErrorMessage
  568. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  569. End Select
  570. CreateWebVDir = Err.Number
  571. Exit Function
  572. End If
  573. ' Check if we have a contiguous name space in the metabase and file system
  574. oScriptHelper.BuildNameSpace strPath
  575. If Err.Number Then
  576. Select Case Err.Number
  577. Case &H80070003
  578. WScript.Echo L_WrongVDirPath_ErrorMessage
  579. Case Else
  580. WScript.Echo L_CannotBuildNameSpace_ErrorMessage
  581. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  582. End Select
  583. CreateWebVDir = Err.Number
  584. Exit Function
  585. End If
  586. ' Remove trailing slash (if present)
  587. If (Right(strRoot, 1) = "\") Then
  588. strRoot = Left(strRoot, Len(strRoot) - 1)
  589. End If
  590. ' Create new web virtual directory
  591. Set vdirClassObj = providerObj.Get("IIsWebVirtualDirSetting")
  592. Set vdirObj = vdirClassObj.SpawnInstance_()
  593. vdirObj.Name = strNewVdir
  594. vdirObj.Path = strRoot
  595. ' Set web virtual directory properties
  596. vdirObj.AuthFlags = 5 ' AuthNTLM + AuthAnonymous
  597. vdirObj.EnableDefaultDoc = True
  598. vdirObj.DirBrowseFlags = &H4000003E ' date, time, size, extension, longdate
  599. vdirObj.AccessFlags = 513 ' read, script
  600. vdirObj.Put_()
  601. ' Create Pooled-proc application on ROOT WebVDir
  602. Set vdirObj = providerObj.Get("IIsWebVirtualDir='" & strNewVdir & "'")
  603. vdirObj.AppCreate2(APP_POOLED)
  604. If Err.Number Then
  605. WScript.Echo L_AppCreate_ErrorMessage
  606. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  607. intResult = ERR_GENERAL_FAILURE
  608. End If
  609. ' Update AppFriendlyName property
  610. Set vdirObj = providerObj.Get("IIsWebVirtualDirSetting='" & strNewVdir & "'")
  611. vdirObj.AppFriendlyName = strAlias
  612. vdirObj.Put_()
  613. ' Remove trailing slash (if present)
  614. If (Right(strVPath, 1) = "/") Then
  615. strVPath = Left(strVPath, Len(strVPath) - 1)
  616. End If
  617. If (strServer = ".") Then
  618. strServer = oScriptHelper.GetEnvironmentVar("%COMPUTERNAME%")
  619. End If
  620. ' Post summary
  621. WScript.Echo L_Server_Message & Space(14 - Len(L_Server_Message)) & "= " & UCase(strServer)
  622. WScript.Echo L_VPath_Message & Space(14 - Len(L_VPath_Message)) & "= " & strVPath & "/" & strAlias
  623. WScript.Echo L_Root_Message & Space(14 - Len(L_Root_Message)) & "= " & strRoot
  624. WScript.Echo L_MetabasePath_Message & Space(14 - Len(L_MetabasePath_Message)) & "= " & strNewVdir
  625. CreateWebVDir = intResult
  626. End Function
  627. '''''''''''''''''''''''''''
  628. ' Helper Functions
  629. '''''''''''''''''''''''''''
  630. '''''''''''''''''''''''''''
  631. ' QueryWebVDir
  632. '''''''''''''''''''''''''''
  633. Function QueryWebVDir(strVDir)
  634. Dim Servers, Server, strQuery
  635. Dim bFirstIteration
  636. Dim vdirObj, providerObj
  637. Dim strServer, strPath, strVDirName
  638. On Error Resume Next
  639. oScriptHelper.WMIConnect
  640. If Err.Number Then
  641. WScript.Echo L_WMIConnect_ErrorMessage
  642. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  643. QueryWebVDir = Err.Number
  644. Exit Function
  645. End If
  646. Set providerObj = oScriptHelper.ProviderObj
  647. strPath = ParseSitePath(strVDir)
  648. If IsEmpty(strPath) Then
  649. ' Got problems parsing the path
  650. WScript.Echo L_SeeQueryHelp_Message
  651. QueryWebVDir = ERR_GENERAL_FAILURE
  652. Exit Function
  653. End If
  654. ' Semi-sync query. (flags = ForwardOnly Or ReturnImediately = &H30)
  655. strQuery = "ASSOCIATORS OF {IIsWebVirtualDir=""" & strPath & """} WHERE ResultClass = IIsWebVirtualDir " & _
  656. "ResultRole = PartComponent"
  657. Set Servers = providerObj.ExecQuery(strQuery, , &H30)
  658. If (Err.Number <> 0) Then
  659. WScript.Echo L_Query_ErrorMessage
  660. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  661. QueryWebVDir = Err.Number
  662. Exit Function
  663. End If
  664. bFirstIteration = True
  665. For Each Server in Servers
  666. If bFirstIteration Then
  667. WScript.Echo L_AliasName_Text & Space(25 - Len(L_AliasName_Text)) & L_Path_Text
  668. WScript.Echo "=============================================================================="
  669. End If
  670. Set vdirObj = providerObj.get("IIsWebVirtualDirSetting=""" & Server.Name & """")
  671. If (Err.Number <> 0) Then
  672. WScript.Echo L_GetSetting_ErrorMessage
  673. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  674. QueryWebVDir = Err.Number
  675. Exit Function
  676. End If
  677. ' If this is the first binding list, print server comment and server name
  678. strVDirName = Replace(vdirObj.Name, strPath, "") ', , , vbTextCompare)
  679. WScript.Echo strVDirName & Space(25 - Len(strVDirName)) & vdirObj.Path
  680. bFirstIteration = False
  681. Next
  682. If bFirstIteration Then
  683. WScript.Echo L_VDirsNotFound_ErrorMessage
  684. End If
  685. QueryWebVDir = ERR_OK
  686. End Function