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.

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