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.

921 lines
35 KiB

  1. '
  2. ' Copyright (c) Microsoft Corporation. All rights reserved.
  3. '
  4. ' VBScript Source File
  5. '
  6. ' Script Name: IIsCnfg.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_ConfImported_Text = "Configuration imported from %1 in file"
  16. Const L_ConfImportedp2_Text = "%1 to %2 in the Metabase."
  17. Const L_ConfExported_Text = "Configuration exported from %1 to file %2."
  18. Const L_MDSaved_Text = "Metadata successfully flushed to disk."
  19. Const L_Error_ErrorMessage = "Error &H%1: %2"
  20. Const L_GetComputerObject_ErrorMessage = "Could not get computer object"
  21. Const L_Import_ErrorMessage = "Error while importing configuration."
  22. Const L_Export_ErrorMessage = "Error while exporting configuration."
  23. Const L_SaveData_ErrorMessage = "Error while flushing metabase."
  24. Const L_OnlyOneOper_ErrorMessage = "Please specify only one operation at a time."
  25. Const L_ScriptHelper_ErrorMessage = "Could not create an instance of the"
  26. Const L_ScriptHelperp2_ErrorMessage = "IIsScriptHelper object."
  27. Const L_ChkScpHelperReg_ErrorMessage = "Please register the Microsoft.IIsScriptHelper"
  28. Const L_ChkScpHelperRegp2_ErrorMessage = "component."
  29. Const L_CmdLib_ErrorMessage = "Could not create an instance of the CmdLib object."
  30. Const L_ChkCmdLibReg_ErrorMessage = "Please register the Microsoft.CmdLib component."
  31. Const L_WMIConnect_ErrorMessage = "Could not connect to WMI provider."
  32. Const L_RequiredArgsMissing_ErrorMessage = "Required arguments are missing."
  33. Const L_FileExpected_ErrorMessage = "Argument is a folder path while expecting a file"
  34. Const L_FileExpectedp2_ErrorMessage = "path."
  35. Const L_ParentFolderDoesntExist_ErrorMessage = "Parent folder doesn't exist."
  36. Const L_FileDoesntExist_ErrorMessage = "Input file doesn't exist."
  37. Const L_FileAlreadyExist_ErrorMessage = "Export file specified already exists."
  38. Const L_NotEnoughParams_ErrorMessage = "Not enough parameters."
  39. Const L_InvalidSwitch_ErrorMessage = "Invalid switch: %1"
  40. Const L_IncorrectPassword_ErrorMessage = "The password specified is incorrect."
  41. Const L_InvalidXML_ErrorMessage = "The import file appears to contain invalid XML."
  42. Const L_Admin_ErrorMessage = "You cannot run this command because you are not an"
  43. Const L_Adminp2_ErrorMessage = "administrator on the server you are trying to configure."
  44. Const L_DriveLetter_Message = "Mapping local drive %1 to admin share on server %2"
  45. Const L_Shell_ErrorMessage = "Could not create an instance of the WScript.Shell"
  46. Const L_Shellp2_ErrorMessage = "object."
  47. Const L_FS_ErrorMessage = "Could not create an instance of the"
  48. Const L_FSp2_ErrorMessage = "Scripting.FileSystemObject object."
  49. Const L_Network_ErrorMessage = "Could not create an instance of the"
  50. Const L_Networkp2_ErrorMessage = "WScript.Network object."
  51. Const L_BackingUp_Message = "Backing up server %1"
  52. Const L_Restoring_Message = "Restoring on server %1"
  53. Const L_Backup_ErrorMessage = "Failure creating backup."
  54. Const L_BackupComplete_Message = "Backup complete."
  55. Const L_Restore_ErrorMessage = "Failure restoring backup."
  56. Const L_RestoreComplete_Message = "Restore complete."
  57. Const L_UnMap_Message = "Unmapping local drive %1"
  58. Const L_NoDrive_ErrorMessage = "No drives available for mapping on local machine."
  59. Const L_Copy_Message = "Copying backup files..."
  60. Const L_Copy_ErrorMessage = "Error copying files."
  61. Const L_ReturnVal_ErrorMessage = "Call returned with code %1"
  62. Const L_CopyComplete_Message = "Copy operation complete."
  63. '''''''''''''''''''''
  64. ' Help
  65. Const L_Empty_Text = ""
  66. ' General help messages
  67. Const L_SeeHelp_Message = "Type IIsCnfg /? for help."
  68. Const L_SeeImportHelp_Message = "Type IIsCnfg /import /? for help."
  69. Const L_SeeExportHelp_Message = "Type IIsCnfg /export /? for help."
  70. Const L_Help_HELP_General01_Text = "Description: Import and export IIS configuration."
  71. Const L_Help_HELP_General02_Text = "Syntax: IIsCnfg [/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_General05_Text = ""
  75. Const L_Help_HELP_General06_Text = "Value Description"
  76. Const L_Help_HELP_General07_Text = "/s <server> Connect to machine <server>."
  77. Const L_Help_HELP_General07p2_Text = " [Default: this system]"
  78. Const L_Help_HELP_General08_Text = "/u <username> Connect as <domain>\<username> or"
  79. Const L_Help_HELP_General09_Text = " <username>. [Default: current user]"
  80. Const L_Help_HELP_General10_Text = "/p <password> Password for the <username> user."
  81. Const L_Help_HELP_General11_Text = "<operation> /import Import configuration from"
  82. Const L_Help_HELP_General11p1_Text = " a configuration file."
  83. Const L_Help_HELP_General12_Text = " /export Export configuration into"
  84. Const L_Help_HELP_General12p1_Text = " a configuration file."
  85. Const L_Help_HELP_General13_Text = " /copy Copy configuration from"
  86. Const L_Help_HELP_General14_Text = " one machine to another."
  87. Const L_Help_HELP_General22_Text = "For detailed usage:"
  88. Const L_Help_HELP_General23_Text = "IIsCnfg /import /?"
  89. Const L_Help_HELP_General24_Text = "IIsCnfg /export /?"
  90. Const L_Help_HELP_General25_Text = "IIsCnfg /copy /?"
  91. Const L_Help_HELP_General26_Text = "IIsCnfg /save /?"
  92. ' Common help messages
  93. Const L_Help_HELP_Common13_Text = "/d <DecryptPass> Specifies the password used to"
  94. Const L_Help_HELP_Common13p1_Text = " decrypt encrypted configuration data."
  95. Const L_Help_HELP_Common13p2_Text = " [Default: """"]"
  96. Const L_Help_HELP_Common14_Text = "/f <File> Configuration file."
  97. Const L_Help_HELP_Common15_Text = "/sp <SourcePath> The full metabase path to start"
  98. Const L_Help_HELP_Common15p1_Text = " reading from the configuration file."
  99. Const L_Help_HELP_Common21_Text = "Examples:"
  100. ' Copy help messages
  101. Const L_Help_HELP_Copy1_Text = "Description: Copy configuration from a source server to a"
  102. Const L_Help_HELP_Copy1p2_Text = " target server."
  103. Const L_Help_HELP_Copy2_Text = "Syntax: iiscnfg [/s <server> [/u <username> [/p <password>]]]"
  104. Const L_Help_HELP_Copy2p2_Text = " /copy /ts <target server> /tu <target user>"
  105. Const L_Help_HELP_Copy2p3_Text = " /tp <target password>"
  106. Const L_Help_HELP_Copy3_Text = "Parameters:"
  107. Const L_Help_HELP_Copy4_Text = "Value Description"
  108. Const L_Help_HELP_Copy5_Text = "/s <server> Connect to machine <server>"
  109. Const L_Help_HELP_Copy5p2_Text = " [Default: this system]"
  110. Const L_Help_HELP_Copy6_Text = "/u <username> Connect as <domain>/<username>"
  111. Const L_Help_HELP_Copy7_Text = " or <username> [Default: current user]"
  112. Const L_Help_HELP_Copy8_Text = "/p <password> Password for the <username> user"
  113. Const L_Help_HELP_Copy9_Text = "/ts Target server to copy configuration to"
  114. Const L_Help_HELP_Copy10_Text = "/tu Username to use when connecting to the"
  115. Const L_Help_HELP_Copy10p2_Text = " target server"
  116. Const L_Help_HELP_Copy11_Text = "/tp Password to use when connecting to the"
  117. Const L_Help_HELP_Copy11p2_Text = " target server"
  118. Const L_Help_HELP_Copy12_Text = "Examples:"
  119. Const L_Help_HELP_Copy13_Text = "iiscnfg.vbs /copy /ts TargetServer /tu Administrator /tp Pk$^("
  120. Const L_Help_HELP_Copy14_Text = "iiscnfg.vbs /s SourceServer /u Administrator /p Kj30W /copy"
  121. Const L_Help_HELP_Copy14p2_Text = " /ts TargetServer /tu Administrator /tp Pk$^j"
  122. ' Import help messages
  123. Const L_Help_HELP_Import01_Text = "Description: Import configuration from a configuration file."
  124. Const L_Help_HELP_Import02_Text = "Syntax: IIsCnfg [/s <server> [/u <username> [/p <password>]]]"
  125. Const L_Help_HELP_Import02p1_Text = " /import [/d <DeCryptPass>] /f <File> /sp <SourcePath>"
  126. Const L_Help_HELP_Import02p2_Text = " /dp <DestPath> [/inherited] [/children] [/merge]"
  127. Const L_Help_HELP_Import16_Text = "/dp <DestPath> The metabase path destination for"
  128. Const L_Help_HELP_Import16p1_Text = " imported properties. If the keytype"
  129. Const L_Help_HELP_Import16p2_Text = " of the SourcePath and the DestPath do"
  130. Const L_Help_HELP_Import16p3_Text = " not match, an error occurs."
  131. Const L_Help_HELP_Import17_Text = "/inherited Import inherited settings if set."
  132. Const L_Help_HELP_Import18_Text = "/children Import configuration for child nodes."
  133. Const L_Help_HELP_Import19_Text = "/merge Merge imported configuration with"
  134. Const L_Help_HELP_Import19p1_Text = " existing configuration."
  135. Const L_Help_HELP_Import22_Text = "IIsCnfg /import /f c:\config.xml /sp /lm/w3svc/5/Root/401Kapp"
  136. Const L_Help_HELP_Import22p1_Text = " /dp /lm/w3svc/1/Root/401Kapp"
  137. ' Export help messages
  138. Const L_Help_HELP_Export01_Text = "Description: Export configuration into a configuration file."
  139. Const L_Help_HELP_Export02_Text = "Syntax: IIsCnfg [/s <server> [/u <username> [/p <password>]]]"
  140. Const L_Help_HELP_Export02p1_Text = " /export [/d <DeCryptPass>] /f <File> /sp <SourcePath>"
  141. Const L_Help_HELP_Export02p2_Text = " [/inherited] [/children]"
  142. Const L_Help_HELP_Export17_Text = "/inherited Export inherited settings if set."
  143. Const L_Help_HELP_Export18_Text = "/children Export configuration for child nodes."
  144. Const L_Help_HELP_Export22_Text = "IIsCnfg /export /f c:\config.xml /sp /lm/w3svc/5/Root/401Kapp"
  145. ' Save help messages
  146. Const L_Help_HELP_Save01_Text = "Description: Save configuration to disk."
  147. Const L_Help_HELP_Save02_Text = "Syntax: iiscnfg [/s <server> [/u <username> [/p <password>]]]"
  148. Const L_Help_HELP_Save02p2_Text = " /save"
  149. Const L_Help_HELP_Save22_Text = "iiscnfg.vbs /save"
  150. Const L_Help_HELP_Save23_Text = "iiscnfg.vbs /s SourceServer /u Administrator /p Kj30W /save"
  151. ''''''''''''''''''''''''
  152. ' Operation codes
  153. Const OPER_IMPORT = 1
  154. Const OPER_EXPORT = 2
  155. Const OPER_COPY = 3
  156. Const OPER_SAVE = 4
  157. ' Import/Export flags
  158. Const IMPORT_EXPORT_INHERITED = 1
  159. Const IMPORT_EXPORT_NODE_ONLY = 2
  160. Const IMPORT_EXPORT_MERGE = 4
  161. '
  162. ' Main block
  163. '
  164. Dim oScriptHelper, oCmdLib
  165. Dim strServer, strUser, strPassword, strSite
  166. Dim strTarServer, strTarUser, strTarPassword
  167. Dim strFile, strDecPass, strSourcePath, strDestPath
  168. Dim intOperation, intResult, intFlags
  169. Dim aArgs, arg
  170. Dim strCmdLineOptions
  171. Dim oError
  172. ' Default values
  173. strServer = "."
  174. strUser = ""
  175. strPassword = ""
  176. strTarServer = ""
  177. strTarUser = ""
  178. strTarPassword = ""
  179. intOperation = 0
  180. strFile = ""
  181. strDecPass = ""
  182. strSourcePath = ""
  183. strDestPath = ""
  184. intFlags = IMPORT_EXPORT_NODE_ONLY
  185. ' Instantiate the CmdLib for output string formatting
  186. Set oCmdLib = CreateObject("Microsoft.CmdLib")
  187. If Err.Number <> 0 Then
  188. WScript.Echo L_CmdLib_ErrorMessage
  189. WScript.Echo L_ChkCmdLibReg_ErrorMessage
  190. WScript.Quit(ERR_GENERAL_FAILURE)
  191. End If
  192. Set oCmdLib.ScriptingHost = WScript.Application
  193. ' Instantiate script helper object
  194. Set oScriptHelper = CreateObject("Microsoft.IIsScriptHelper")
  195. If Err.Number <> 0 Then
  196. WScript.Echo L_ScriptHelper_ErrorMessage
  197. WScript.Echo L_ScriptHelperp2_ErrorMessage
  198. WScript.Echo L_ChkScpHelperReg_ErrorMessage
  199. WScript.Echo L_ChkScpHelperRegp2_ErrorMessage
  200. WScript.Quit(ERR_GENERAL_FAILURE)
  201. End If
  202. Set oScriptHelper.ScriptHost = WScript
  203. ' Check if we are being run with cscript.exe instead of wscript.exe
  204. oScriptHelper.CheckScriptEngine
  205. ' Minimum number of parameters must exist
  206. If WScript.Arguments.Count < 1 Then
  207. WScript.Echo L_RequiredArgsMissing_ErrorMessage
  208. WScript.Echo L_SeeHelp_Message
  209. WScript.Quit(ERR_GENERAL_FAILURE)
  210. End If
  211. strCmdLineOptions = "[server:s:1;user:u:1;password:p:1];decpass:d:1;file:f:1;sourcepath:sp:1;" & _
  212. "inherited:i:0;children:c:0;[import::0;destpath:dp:1;merge:m:0];save::0;" & _
  213. "export::0;[copy::0;targetserver:ts:1;targetuser:tu:1;targetpassword:tp:1]"
  214. Set oError = oScriptHelper.ParseCmdLineOptions(strCmdLineOptions)
  215. If Not oError Is Nothing Then
  216. If oError.ErrorCode = oScriptHelper.ERROR_NOT_ENOUGH_ARGS Then
  217. ' Not enough arguments for a specified switch
  218. WScript.Echo L_NotEnoughParams_ErrorMessage
  219. WScript.Echo L_SeeHelp_Message
  220. Else
  221. ' Invalid switch
  222. oCmdLib.vbPrintf L_InvalidSwitch_ErrorMessage, Array(oError.SwitchName)
  223. WScript.Echo L_SeeHelp_Message
  224. End If
  225. WScript.Quit(ERR_GENERAL_FAILURE)
  226. End If
  227. If oScriptHelper.GlobalHelpRequested Then
  228. DisplayHelpMessage
  229. WScript.Quit(ERR_OK)
  230. End If
  231. For Each arg In oScriptHelper.Switches
  232. Select Case arg
  233. Case "server"
  234. ' Server information
  235. strServer = oScriptHelper.GetSwitch(arg)
  236. Case "user"
  237. ' User information
  238. strUser = oScriptHelper.GetSwitch(arg)
  239. Case "password"
  240. ' Password information
  241. strPassword = oScriptHelper.GetSwitch(arg)
  242. Case "targetserver"
  243. ' Server information
  244. strTarServer = oScriptHelper.GetSwitch(arg)
  245. Case "targetuser"
  246. ' User information
  247. strTarUser = oScriptHelper.GetSwitch(arg)
  248. Case "targetpassword"
  249. ' Password information
  250. strTarPassword = oScriptHelper.GetSwitch(arg)
  251. Case "import"
  252. If (intOperation <> 0) Then
  253. WScript.Echo L_OnlyOneOper_ErrorMessage
  254. WScript.Echo L_SeeHelp_Message
  255. WScript.Quit(ERR_GENERAL_FAILURE)
  256. End If
  257. intOperation = OPER_IMPORT
  258. If oScriptHelper.IsHelpRequested(arg) Then
  259. DisplayImportHelpMessage
  260. WScript.Quit(ERR_OK)
  261. End If
  262. Case "export"
  263. If (intOperation <> 0) Then
  264. WScript.Echo L_OnlyOneOper_ErrorMessage
  265. WScript.Echo L_SeeHelp_Message
  266. WScript.Quit(ERR_GENERAL_FAILURE)
  267. End If
  268. intOperation = OPER_EXPORT
  269. If oScriptHelper.IsHelpRequested(arg) Then
  270. DisplayExportHelpMessage
  271. WScript.Quit(ERR_OK)
  272. End If
  273. Case "copy"
  274. If (intOperation <> 0) Then
  275. WScript.Echo L_OnlyOneOper_ErrorMessage
  276. WScript.Echo L_SeeHelp_Message
  277. WScript.Quit(ERR_GENERAL_FAILURE)
  278. End If
  279. intOperation = OPER_COPY
  280. If oScriptHelper.IsHelpRequested(arg) Then
  281. DisplayCopyHelpMessage
  282. WScript.Quit(ERR_OK)
  283. End If
  284. Case "save"
  285. If (intOperation <> 0) Then
  286. WScript.Echo L_OnlyOneOper_ErrorMessage
  287. WScript.Echo L_SeeHelp_Message
  288. WScript.Quit(ERR_GENERAL_FAILURE)
  289. End If
  290. intOperation = OPER_SAVE
  291. If oScriptHelper.IsHelpRequested(arg) Then
  292. DisplaySaveHelpMessage
  293. WScript.Quit(ERR_OK)
  294. End If
  295. Case "file"
  296. strFile = oScriptHelper.GetSwitch(arg)
  297. Case "decpass"
  298. strDecPass = oScriptHelper.GetSwitch(arg)
  299. Case "sourcepath"
  300. strSourcePath = oScriptHelper.GetSwitch(arg)
  301. Case "destpath"
  302. strDestPath = oScriptHelper.GetSwitch(arg)
  303. Case "inherited"
  304. intFlags = intFlags Or IMPORT_EXPORT_INHERITED
  305. Case "children"
  306. intFlags = intFlags And Not IMPORT_EXPORT_NODE_ONLY
  307. Case "merge"
  308. intFlags = intFlags Or IMPORT_EXPORT_MERGE
  309. End Select
  310. Next
  311. ' Check Parameters
  312. If intOperation = 0 Then
  313. WScript.Echo L_OperationRequired_ErrorMessage
  314. WScript.Echo L_SeeHelp_Message
  315. WScript.Quit(ERR_GENERAL_FAILURE)
  316. End If
  317. If intOperation = OPER_SAVE Then
  318. ElseIf intOperation = OPER_COPY Then
  319. If strTarServer = "" Or strTarUser = "" Or strTarPassword = "" Then
  320. WScript.Echo L_RequiredArgsMissing_ErrorMessage
  321. WScript.Quit(ERR_GENERAL_FAILURE)
  322. End If
  323. Else
  324. If strFile = "" Or strSourcePath = "" Or (intOperation = OPER_IMPORT And strDestPath = "") Then
  325. WScript.Echo L_RequiredArgsMissing_ErrorMessage
  326. If intOperation = OPER_IMPORT Then
  327. WScript.Echo L_SeeImportHelp_Message
  328. Else
  329. WScript.Echo L_SeeExportHelp_Message
  330. End If
  331. WScript.Quit(ERR_GENERAL_FAILURE)
  332. End If
  333. End If
  334. ' Check if /p is specified but /u isn't. In this case, we should bail out with an error
  335. If oScriptHelper.Switches.Exists("password") And Not oScriptHelper.Switches.Exists("user") Then
  336. WScript.Echo L_PassWithoutUser_ErrorMessage
  337. WScript.Quit(ERR_GENERAL_FAILURE)
  338. End If
  339. ' Check if /u is specified but /p isn't. In this case, we should ask for a password
  340. If oScriptHelper.Switches.Exists("user") And Not oScriptHelper.Switches.Exists("password") Then
  341. strPassword = oCmdLib.GetPassword
  342. End If
  343. ' Initializes authentication with remote machine
  344. intResult = oScriptHelper.InitAuthentication(strServer, strUser, strPassword)
  345. If intResult <> 0 Then
  346. WScript.Quit(intResult)
  347. End If
  348. ' Choose operation
  349. Select Case intOperation
  350. Case OPER_IMPORT
  351. intResult = Import(strDecPass, strFile, strSourcePath, strDestPath, intFlags)
  352. Case OPER_EXPORT
  353. intResult = Export(strDecPass, strFile, strSourcePath, intFlags)
  354. Case OPER_COPY
  355. intResult = Repl(strServer, strUser, strPassword, strTarServer, strTarUser, strTarPassword)
  356. Case OPER_SAVE
  357. intResult = SaveMD()
  358. End Select
  359. ' Return value to command processor
  360. WScript.Quit(intResult)
  361. '''''''''''''''''''''''''
  362. ' End Of Main Block
  363. '''''''''''''''''''''
  364. '''''''''''''''''''''''''''
  365. ' DisplayHelpMessage
  366. '''''''''''''''''''''''''''
  367. Sub DisplayHelpMessage()
  368. WScript.Echo L_Help_HELP_General01_Text
  369. WScript.Echo L_Empty_Text
  370. WScript.Echo L_Help_HELP_General02_Text
  371. WScript.Echo L_Help_HELP_General03_Text
  372. WScript.Echo L_Empty_Text
  373. WScript.Echo L_Help_HELP_General04_Text
  374. WScript.Echo L_Help_HELP_General05_Text
  375. WScript.Echo L_Help_HELP_General06_Text
  376. WScript.Echo L_Help_HELP_General07_Text
  377. WScript.Echo L_Help_HELP_General07p2_Text
  378. WScript.Echo L_Help_HELP_General08_Text
  379. WScript.Echo L_Help_HELP_General09_Text
  380. WScript.Echo L_Help_HELP_General10_Text
  381. WScript.Echo L_Help_HELP_General11_Text
  382. WScript.Echo L_Help_HELP_General11p1_Text
  383. WScript.Echo L_Help_HELP_General12_Text
  384. WScript.Echo L_Help_HELP_General12p1_Text
  385. WScript.Echo L_Help_HELP_General13_Text
  386. WScript.Echo L_Help_HELP_General14_Text
  387. WScript.Echo L_Empty_Text
  388. WScript.Echo L_Help_HELP_General22_Text
  389. WScript.Echo L_Empty_Text
  390. WScript.Echo L_Help_HELP_General23_Text
  391. WScript.Echo L_Help_HELP_General24_Text
  392. WScript.Echo L_Help_HELP_General25_Text
  393. WScript.Echo L_Help_HELP_General26_Text
  394. End Sub
  395. Sub DisplayImportHelpMessage()
  396. WScript.Echo L_Help_HELP_Import01_Text
  397. WScript.Echo L_Empty_Text
  398. WScript.Echo L_Help_HELP_Import02_Text
  399. WScript.Echo L_Help_HELP_Import02p1_Text
  400. WScript.Echo L_Help_HELP_Import02p2_Text
  401. WScript.Echo L_Empty_Text
  402. WScript.Echo L_Help_HELP_General06_Text
  403. WScript.Echo L_Help_HELP_General07_Text
  404. WScript.Echo L_Help_HELP_General07p2_Text
  405. WScript.Echo L_Help_HELP_General08_Text
  406. WScript.Echo L_Help_HELP_General09_Text
  407. WScript.Echo L_Help_HELP_General10_Text
  408. WScript.Echo L_Help_HELP_Common13_Text
  409. WScript.Echo L_Help_HELP_Common13p1_Text
  410. WScript.Echo L_Help_HELP_Common13p2_Text
  411. WScript.Echo L_Help_HELP_Common14_Text
  412. WScript.Echo L_Help_HELP_Common15_Text
  413. WScript.Echo L_Help_HELP_Common15p1_Text
  414. WScript.Echo L_Help_HELP_Import16_Text
  415. WScript.Echo L_Help_HELP_Import16p1_Text
  416. WScript.Echo L_Help_HELP_Import16p2_Text
  417. WScript.Echo L_Help_HELP_Import16p3_Text
  418. WScript.Echo L_Help_HELP_Import17_Text
  419. WScript.Echo L_Help_HELP_Import18_Text
  420. WScript.Echo L_Help_HELP_Import19_Text
  421. WScript.Echo L_Help_HELP_Import19p1_Text
  422. WScript.Echo L_Empty_Text
  423. WScript.Echo L_Help_HELP_Common21_Text
  424. WScript.Echo L_Empty_Text
  425. WScript.Echo L_Help_HELP_Import22_Text
  426. WScript.Echo L_Help_HELP_Import22p1_Text
  427. End Sub
  428. Sub DisplayCopyHelpMessage()
  429. WScript.Echo L_Help_HELP_Copy1_Text
  430. WScript.Echo L_Help_HELP_Copy1p2_Text
  431. WScript.Echo L_Empty_Text
  432. WScript.Echo L_Help_HELP_Copy2_Text
  433. WScript.Echo L_Help_HELP_Copy2p2_Text
  434. WScript.Echo L_Help_HELP_Copy2p3_Text
  435. WScript.Echo L_Help_HELP_Copy3_Text
  436. WScript.Echo L_Empty_Text
  437. WScript.Echo L_Help_HELP_Copy4_Text
  438. WScript.Echo L_Help_HELP_Copy5_Text
  439. WScript.Echo L_Help_HELP_Copy5p2_Text
  440. WScript.Echo L_Help_HELP_Copy6_Text
  441. WScript.Echo L_Help_HELP_Copy7_Text
  442. WScript.Echo L_Help_HELP_Copy8_Text
  443. WScript.Echo L_Help_HELP_Copy9_Text
  444. WScript.Echo L_Help_HELP_Copy10_Text
  445. WScript.Echo L_Help_HELP_Copy10p2_Text
  446. WScript.Echo L_Help_HELP_Copy11_Text
  447. WScript.Echo L_Help_HELP_Copy11p2_Text
  448. WScript.Echo L_Empty_Text
  449. WScript.Echo L_Help_HELP_Copy12_Text
  450. WScript.Echo L_Empty_Text
  451. WScript.Echo L_Help_HELP_Copy13_Text
  452. WScript.Echo L_Help_HELP_Copy14_Text
  453. WScript.Echo L_Help_HELP_Copy14p2_Text
  454. End Sub
  455. Sub DisplayExportHelpMessage()
  456. WScript.Echo L_Help_HELP_Export01_Text
  457. WScript.Echo L_Empty_Text
  458. WScript.Echo L_Help_HELP_Export02_Text
  459. WScript.Echo L_Help_HELP_Export02p1_Text
  460. WScript.Echo L_Help_HELP_Export02p2_Text
  461. WScript.Echo L_Empty_Text
  462. WScript.Echo L_Help_HELP_General06_Text
  463. WScript.Echo L_Help_HELP_General07_Text
  464. WScript.Echo L_Help_HELP_General07p2_Text
  465. WScript.Echo L_Help_HELP_General08_Text
  466. WScript.Echo L_Help_HELP_General09_Text
  467. WScript.Echo L_Help_HELP_General10_Text
  468. WScript.Echo L_Help_HELP_Common13_Text
  469. WScript.Echo L_Help_HELP_Common13p1_Text
  470. WScript.Echo L_Help_HELP_Common13p2_Text
  471. WScript.Echo L_Help_HELP_Common14_Text
  472. WScript.Echo L_Help_HELP_Common15_Text
  473. WScript.Echo L_Help_HELP_Common15p1_Text
  474. WScript.Echo L_Help_HELP_Export17_Text
  475. WScript.Echo L_Help_HELP_Export18_Text
  476. WScript.Echo L_Empty_Text
  477. WScript.Echo L_Help_HELP_Common21_Text
  478. WScript.Echo L_Empty_Text
  479. WScript.Echo L_Help_HELP_Export22_Text
  480. End Sub
  481. Sub DisplaySaveHelpMessage()
  482. WScript.Echo L_Help_HELP_Save01_Text
  483. WScript.Echo L_Empty_Text
  484. WScript.Echo L_Help_HELP_Save02_Text
  485. WScript.Echo L_Help_HELP_Save02p2_Text
  486. WScript.Echo L_Empty_Text
  487. WScript.Echo L_Help_HELP_General06_Text
  488. WScript.Echo L_Help_HELP_General07_Text
  489. WScript.Echo L_Help_HELP_General07p2_Text
  490. WScript.Echo L_Help_HELP_General08_Text
  491. WScript.Echo L_Help_HELP_General09_Text
  492. WScript.Echo L_Help_HELP_General10_Text
  493. WScript.Echo L_Empty_Text
  494. WScript.Echo L_Help_HELP_Common21_Text
  495. WScript.Echo L_Empty_Text
  496. WScript.Echo L_Help_HELP_Save22_Text
  497. WScript.Echo L_Help_HELP_Save23_Text
  498. End Sub
  499. '''''''''''''''''''''''''''
  500. ' Copy Function
  501. '''''''''''''''''''''''''''
  502. Function Repl(strSourceServer, strSourceUser, strSourcePwd, strDestServer, strDestUser, strDestPwd)
  503. If (strSourceServer = ".") Then
  504. strSourceServer = ""
  505. End If
  506. ' Do the first backup
  507. Dim strBackupCommand
  508. Dim strSourceDrive, strDrvLetter, strSourcePath
  509. Dim oShell, oFS, oNetwork
  510. Dim strDestDrive, strDestPath
  511. Dim strCopyCommand, strDelCommand, strRestoreCommand
  512. Set oShell = WScript.CreateObject("WScript.Shell")
  513. If Err.Number <> 0 Then
  514. WScript.Echo L_Shell_ErrorMessage
  515. WScript.Echo L_Shellp2_ErrorMessage
  516. WScript.Quit(ERR_GENERAL_FAILURE)
  517. End If
  518. Set oFS = WScript.CreateObject("Scripting.FileSystemObject")
  519. If Err.Number <> 0 Then
  520. WScript.Echo L_FS_ErrorMessage
  521. WScript.Echo L_FSp2_ErrorMessage
  522. WScript.Quit(ERR_GENERAL_FAILURE)
  523. End If
  524. Set oNetwork = WScript.CreateObject("WScript.Network")
  525. If Err.Number <> 0 Then
  526. WScript.Echo L_Network_ErrorMessage
  527. WScript.Echo L_Networkp2_ErrorMessage
  528. WScript.Quit(ERR_GENERAL_FAILURE)
  529. End If
  530. strBackupCommand = "cmd /c %SystemRoot%\system32\cscript.exe %SystemRoot%\system32\iisback.vbs /backup"
  531. If strSourceServer <> "" Then
  532. strBackupCommand = strBackupCommand & " /s " & strSourceServer
  533. Else
  534. strSourceServer = "127.0.0.1"
  535. End If
  536. If strSourceUser <> "" Then
  537. strBackupCommand = strBackupCommand & " /u " & strSourceUser
  538. End If
  539. If strSourcePwd <> "" Then
  540. strBackupCommand = strBackupCommand & " /p " & strSourcePwd
  541. End If
  542. ' need overwrite in case a previous attempt failed
  543. strBackupCommand = strBackupCommand & " /b iisreplback /overwrite"
  544. ' backup the source server
  545. oCmdLib.vbPrintf L_BackingUp_Message, Array(strSourceServer)
  546. intResult = oShell.Run(strBackupCommand, 1, TRUE)
  547. WScript.Echo L_BackupComplete_Message
  548. ' Now map drive to source server
  549. ' Find a drive letter
  550. strSourceDrive = "NO DRIVE"
  551. For strDrvLetter = Asc("C") to Asc("Z")
  552. If Not oFS.DriveExists(Chr(strDrvLetter)) Then
  553. strSourceDrive = Chr(strDrvLetter)
  554. Exit For
  555. End If
  556. Next
  557. If strSourceDrive = "NO DRIVE" Then
  558. ' No drive letter available
  559. WScript.Echo L_NoDrive_ErrorMessage
  560. WScript.Quit(ERR_GENERAL_FAILURE)
  561. End If
  562. strSourceDrive = strSourceDrive & ":"
  563. strSourcePath = "\\" & strSourceServer & "\ADMIN$"
  564. ' Map the drive
  565. oCmdLib.vbPrintf L_DriveLetter_Message, Array(strSourceDrive, strSourceServer)
  566. If strSourceUser <> "" Then
  567. oNetwork.MapNetworkDrive strSourceDrive, strSourcePath, FALSE, strSourceUser, strSourcePwd
  568. Else
  569. oNetwork.MapNetworkDrive strSourceDrive, strSourcePath
  570. End If
  571. ' Now map drive to destination server
  572. ' Find a drive letter
  573. strDestDrive = "NO DRIVE"
  574. For strDrvLetter = Asc("C") to Asc("Z")
  575. If Not oFS.DriveExists(Chr(strDrvLetter)) Then
  576. strDestDrive = Chr(strDrvLetter)
  577. Exit For
  578. End If
  579. Next
  580. If strDestDrive = "NO DRIVE" Then
  581. ' No drive letter available
  582. WScript.Echo L_NoDrive_ErrorMessage
  583. WScript.Quit(ERR_GENERAL_FAILURE)
  584. End If
  585. strDestDrive = strDestDrive & ":"
  586. strDestPath = "\\" & strDestServer & "\ADMIN$"
  587. ' Map the drive
  588. oCmdLib.vbPrintf L_DriveLetter_Message, Array(strDestDrive, strDestServer)
  589. If strDestUser <> "" Then
  590. oNetwork.MapNetworkDrive strDestDrive, strDestPath, FALSE, strDestUser, strDestPwd
  591. Else
  592. oNetwork.MapNetworkDrive strDestDrive, strDestPath
  593. End If
  594. strCopyCommand = "cmd /c copy /Y " & strSourceDrive & "\system32\inetsrv\metaback\iisreplback.* "
  595. strCopyCommand = strCopyCommand & strDestDrive & "\system32\inetsrv\metaback"
  596. ' Copy the files
  597. WScript.Echo L_Copy_Message
  598. WScript.Echo strCopyCommand
  599. intResult = oShell.Run(strCopyCommand, 1, TRUE)
  600. If intResult <> 0 Then
  601. oCmdLib.vbPrintf L_ReturnVal_ErrorMessage, Array(intResult)
  602. WScript.Echo L_Copy_ErrorMessage
  603. WScript.Quit(intResult)
  604. End If
  605. strDelCommand = "cmd /c del /f /q " & strSourceDrive & "\system32\inetsrv\metaback\iisreplback.*"
  606. intResult = oShell.Run(strDelCommand, 1, TRUE)
  607. ' Unmap drive to source server
  608. oCmdLib.vbPrintf L_UnMap_Message, Array(strSourceDrive)
  609. oNetwork.RemoveNetworkDrive strSourceDrive
  610. ' Now do the restore on the destination server
  611. strRestoreCommand = "cmd /c %SystemRoot%\system32\cscript.exe %SystemRoot%\system32\iisback.vbs /restore /s " & strDestServer
  612. strRestoreCommand = strRestoreCommand & " /u " & strDestUser
  613. strRestoreCommand = strRestoreCommand & " /p " & strDestPwd
  614. strRestoreCommand = strRestoreCommand & " /b iisreplback"
  615. oCmdLib.vbPrintf L_Restoring_Message, Array(strDestServer)
  616. intResult = oShell.Run(strRestoreCommand, 1, TRUE)
  617. If intResult <> 0 Then
  618. oCmdLib.vbPrintf L_ReturnVal_ErrorMessage, Array(intResult)
  619. WScript.Echo L_Restore_ErrorMessage
  620. WScript.Quit(intResult)
  621. End If
  622. WScript.Echo L_RestoreComplete_Message
  623. strDelCommand = "cmd /c del /f /q " & strDestDrive & "\system32\inetsrv\metaback\iisreplback.*"
  624. intResult = oShell.Run(strDelCommand, 1, TRUE)
  625. ' Unmap drive to destination server
  626. oCmdLib.vbPrintf L_UnMap_Message, Array(strDestDrive)
  627. oNetwork.RemoveNetworkDrive strDestDrive
  628. WScript.Echo L_CopyComplete_Message
  629. End Function
  630. '''''''''''''''''''''''''''
  631. ' Import Function
  632. '''''''''''''''''''''''''''
  633. Function Import(strDecPass, strFile, strSourcePath, strDestPath, intFlags)
  634. Dim ComputerObj
  635. Dim strFilePath
  636. On Error Resume Next
  637. ' Normalize path first
  638. strFilePath = oScriptHelper.NormalizeFilePath(strFile)
  639. If Err Then
  640. Select Case Err.Number
  641. Case &H80070002
  642. WScript.Echo L_FileExpected_ErrorMessage
  643. WScript.Echo L_FileExpectedp2_ErrorMessage
  644. Case &H80070003
  645. WScript.Echo L_ParentFolderDoesntExist_ErrorMessage
  646. End Select
  647. Import = Err.Number
  648. Exit Function
  649. End If
  650. oScriptHelper.WMIConnect
  651. If Err.Number Then
  652. WScript.Echo L_WMIConnect_ErrorMessage
  653. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  654. Import = Err.Number
  655. Exit Function
  656. End If
  657. Set ComputerObj = oScriptHelper.ProviderObj.get("IIsComputer='LM'")
  658. If Err.Number Then
  659. Select Case Err.Number
  660. Case &H80070005
  661. WScript.Echo L_Admin_ErrorMessage
  662. WScript.Echo L_Adminp2_ErrorMessage
  663. Case Else
  664. WScript.Echo L_GetComputerObj_ErrorMessage
  665. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  666. End Select
  667. Import = Err.Number
  668. Exit Function
  669. End If
  670. ' Call Import method from the computer object
  671. ComputerObj.Import strDecPass, strFilePath, strSourcePath, strDestPath, intFlags
  672. If Err.Number Then
  673. Select Case Err.Number
  674. Case &H80070002
  675. WScript.Echo L_FileDoesntExist_ErrorMessage
  676. Case &H8007052B
  677. WScript.Echo L_IncorrectPassword_ErrorMessage
  678. Case &H800CC819
  679. WScript.Echo L_InvalidXML_ErrorMessage
  680. Case Else
  681. WScript.Echo L_Import_ErrorMessage
  682. WScript.Echo Err.Description
  683. End Select
  684. Import = Err.Number
  685. Exit Function
  686. End If
  687. oCmdLib.vbPrintf L_ConfImported_Text, Array(strSourcePath)
  688. oCmdLib.vbPrintf L_ConfImportedp2_Text, Array(strFile, strDestPath)
  689. End Function
  690. '''''''''''''''''''''''''''
  691. ' Export Function
  692. '''''''''''''''''''''''''''
  693. Function Export(strDecPass, strFile, strSourcePath, intFlags)
  694. Dim ComputerObj
  695. Dim strFilePath
  696. On Error Resume Next
  697. ' Normalize path first
  698. strFilePath = oScriptHelper.NormalizeFilePath(strFile)
  699. If Err Then
  700. Select Case Err.Number
  701. Case &H80070002
  702. WScript.Echo L_FileExpected_ErrorMessage
  703. WScript.Echo L_FileExpectedp2_ErrorMessage
  704. Case &H80070003
  705. WScript.Echo L_ParentFolderDoesntExist_ErrorMessage
  706. End Select
  707. Export = Err.Number
  708. Exit Function
  709. End If
  710. If oScriptHelper.FSObj.FileExists(strFilePath) Then
  711. WScript.Echo L_FileAlreadyExist_ErrorMessage
  712. Export = &H80070050
  713. Exit Function
  714. End If
  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. Export = Err.Number
  720. Exit Function
  721. End If
  722. Set ComputerObj = oScriptHelper.ProviderObj.get("IIsComputer='LM'")
  723. If Err.Number Then
  724. Select Case Err.Number
  725. Case &H80070005
  726. WScript.Echo L_Admin_ErrorMessage
  727. WScript.Echo L_Adminp2_ErrorMessage
  728. Case Else
  729. WScript.Echo L_GetComputerObj_ErrorMessage
  730. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  731. End Select
  732. Export = Err.Number
  733. Exit Function
  734. End If
  735. ' Call Import method from the computer object
  736. ComputerObj.Export strDecPass, strFilePath, strSourcePath, intFlags
  737. If Err.Number Then
  738. WScript.Echo L_Export_ErrorMessage
  739. WScript.Echo Err.Description
  740. Export = Err.Number
  741. Exit Function
  742. End If
  743. oCmdLib.vbPrintf L_ConfExported_Text, Array(strSourcePath, strFile)
  744. End Function
  745. '''''''''''''''''''''''''''
  746. ' SaveMD Function
  747. '''''''''''''''''''''''''''
  748. Function SaveMD()
  749. Dim ComputerObj
  750. On Error Resume Next
  751. oScriptHelper.WMIConnect
  752. If Err.Number Then
  753. WScript.Echo L_WMIConnect_ErrorMessage
  754. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  755. SaveMD = Err.Number
  756. Exit Function
  757. End If
  758. Set ComputerObj = oScriptHelper.ProviderObj.get("IIsComputer='LM'")
  759. If Err.Number Then
  760. Select Case Err.Number
  761. Case &H80070005
  762. WScript.Echo L_Admin_ErrorMessage
  763. WScript.Echo L_Adminp2_ErrorMessage
  764. Case Else
  765. WScript.Echo L_GetComputerObj_ErrorMessage
  766. oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
  767. End Select
  768. SaveMD = Err.Number
  769. Exit Function
  770. End If
  771. ' Call Import method from the computer object
  772. ComputerObj.SaveData
  773. If Err.Number Then
  774. WScript.Echo L_SaveData_ErrorMessage
  775. WScript.Echo Err.Description
  776. SaveMD = Err.Number
  777. Exit Function
  778. End If
  779. WScript.Echo L_MDSaved_Text
  780. End Function