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.

846 lines
30 KiB

  1. '
  2. ' Copyright (c) Microsoft Corporation. All rights reserved.
  3. '
  4. ' VBScript Source File
  5. '
  6. ' Script Name: IIsBack.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_SwitchNeedArg_ErrorMessage = "Switch needs argument."
  16. Const L_Backup_Text = "Backup"
  17. Const L_Version_Text = "version"
  18. Const L_HasBeen_Message = "has been"
  19. Const L_Created_Text = "CREATED"
  20. Const L_Restored_Text = "RESTORED"
  21. Const L_Deleted_Text = "DELETED"
  22. Const L_BackupName_Text = "Backup Name"
  23. Const L_BackupVersion_Text = "Version #"
  24. Const L_DateTime_Text = "Date/Time"
  25. Const L_Error_ErrorMessage = "Error"
  26. Const L_OperationRequired_ErrorMessage = "Please specify an operation before the arguments."
  27. Const L_MinInfoNeeded_ErrorMessage = "Need at least <BackupName>."
  28. Const L_NeedNameVersion_ErrorMessage = "Need at least <BackupName> and <BackupVersion>."
  29. Const L_NotEnoughParams_ErrorMessage = "Not enough parameters."
  30. Const L_OnlyOneOper_ErrorMessage = "Please specify only one operation at a time."
  31. Const L_ComputerObj_ErrorMessage = "Unable to get computer object."
  32. Const L_Backup_ErrorMessage = "Unable to backup metabase."
  33. Const L_Restore_ErrorMessage = "Unable to restore metabase."
  34. Const L_Delete_ErrorMessage = "Unable to delete metabase backup."
  35. Const L_List_ErrorMessage = "Unable to list metabase backups."
  36. Const L_NoBackups_Message = "No backups exist."
  37. Const L_ScriptHelper_ErrorMessage = "Could not create an instance of the IIsScriptHelper object."
  38. Const L_ChkScpHelperReg_ErrorMessage = "Please register the Microsoft.IIsScriptHelper component."
  39. Const L_CmdLib_ErrorMessage = "Unable to create instance of the CmdLib object."
  40. Const L_PassWithoutUser_ErrorMessage = "Please specify /u switch before using /p."
  41. Const L_WMIConnect_ErrorMessage = "Could not connect to WMI provider."
  42. Const L_BackupNotFound_ErrorMessage = "Backup doesn't exist. HIGHEST_VERSION only works with an existent backup."
  43. Const L_VersionTooBig_ErrorMessage = "Version number is too big."
  44. Const L_InvalidVersion_ErrorMessage = "Invalid version number."
  45. Const L_InvalidBackupName_ErrorMessage = "Invalid backup name."
  46. Const L_IncorrectPassword_ErrorMessage = "The password specified is incorrect."
  47. Const L_BackupExists_ErrorMessage = "Backup already exists. Please specify another name or use /overwrite."
  48. Const L_InvalidSwitch_ErrorMessage = "Invalid switch: "
  49. '''''''''''''''''''''
  50. ' Help
  51. ' General help messages
  52. Const L_SeeHelp_Message = "Type IIsBack /? for help."
  53. Const L_SeeBackupHelp_Message = "Type IIsBack /backup /? for help."
  54. Const L_SeeRestoreHelp_Message = "Type IIsBack /restore /? for help."
  55. Const L_SeeDeleteHelp_Message = "Type IIsBack /delete /? for help."
  56. Const L_SeeListHelp_Message = "Type IIsBack /list /? for help."
  57. Const L_Help_HELP_General01_Text = "Description: backup/restore IIS configuration, delete backups, list all backups"
  58. Const L_Help_HELP_General02_Text = "Syntax: IIsBack [/s <server> [/u <username> [/p <password>]]] /<operation>"
  59. Const L_Help_HELP_General03_Text = " [arguments]"
  60. Const L_Help_HELP_General04_Text = "Parameters:"
  61. Const L_Help_HELP_General06_Text = "Value Description"
  62. Const L_Help_HELP_General07_Text = "/s <server> Connect to machine <server> [Default: this system]"
  63. Const L_Help_HELP_General08_Text = "/u <username> Connect as <username> or <domain>\<username>"
  64. Const L_Help_HELP_General09_Text = " [Default: current user]"
  65. Const L_Help_HELP_General10_Text = "/p <password> Password for the <username> user"
  66. Const L_Help_HELP_General11_Text = "<operation> /backup Backup the IIS Server (includes all"
  67. Const L_Help_HELP_General12_Text = " site data and settings)."
  68. Const L_Help_HELP_General13_Text = " /restore Restore the IIS Server from backup"
  69. Const L_Help_HELP_General14_Text = " (overwrites all site data and settings)."
  70. Const L_Help_HELP_General15_Text = " /delete Deletes a backup."
  71. Const L_Help_HELP_General16_Text = " /list List all backups."
  72. Const L_Help_HELP_General17_Text = "For detailed usage:"
  73. Const L_Help_HELP_General18_Text = "IIsBack /backup /?"
  74. Const L_Help_HELP_General19_Text = "IIsBack /restore /?"
  75. Const L_Help_HELP_General20_Text = "IIsBack /delete /?"
  76. Const L_Help_HELP_General21_Text = "IIsBack /list /?"
  77. ' Common to all status change commands
  78. Const L_Help_HELP_Common17_Text = "/b <BackupName> Description for the backup file."
  79. Const L_Help_HELP_Common17p1_Text = " [Default: ""SampleBackup""]"
  80. 'Const L_Help_HELP_Common10_Text = " This virtual path must already exist."
  81. Const L_Help_HELP_Common11_Text = "Examples:"
  82. ' Backup help messages
  83. Const L_Help_HELP_Backup01_Text = "Description: Backup the IIS Server (includes all site data and settings)."
  84. Const L_Help_HELP_Backup02_Text = "Syntax: IIsBack [/s <server> [/u <username> [/p <password>]]] /backup"
  85. Const L_Help_HELP_Backup02p1_Text = " [/b <BackupName>] [/v <VersionNumber>] [/e <BackupPassword>]"
  86. Const L_Help_HELP_Backup02p2_Text = " [/overwrite]"
  87. Const L_Help_HELP_Backup18_Text = "/v <VersionNumber> Specifies the version number to be assigned to"
  88. Const L_Help_HELP_Backup18p1_Text = " the backup. Can be any integer, HIGHEST_VERSION,"
  89. Const L_Help_HELP_Backup18p2_Text = " or NEXT_VERSION. [Default: NEXT_VERSION]"
  90. Const L_Help_HELP_Backup19_Text = "/e <BackupPassword> Encrypt the backup file with the provided password"
  91. 'Const L_Help_HELP_Backup19p1_Text = " instead of encrypting using the machine key"
  92. Const L_Help_HELP_Backup20_Text = "/overwrite Back up even if a backup of the same name and"
  93. Const L_Help_HELP_Backup20p1_Text = " version exists in the specified location,"
  94. Const L_Help_HELP_Backup20p2_Text = " overwriting if necessary. [Default: disabled]"
  95. Const L_Help_HELP_Backup21_Text = "IIsBack /backup"
  96. Const L_Help_HELP_Backup22_Text = "IIsBack /s Server1 /u Administrator /p p@ssW0rd /backup /b NewBackup"
  97. ' Restore help messages
  98. Const L_Help_HELP_Restore01_Text = "Description: Restore the IIS Server from backup (overwrites all site data"
  99. Const L_Help_HELP_Restore01p1_Text = " and settings)."
  100. Const L_Help_HELP_Restore02_Text = "Syntax: IIsBack [/s <server> [/u <username> [/p <password>]]] /restore"
  101. Const L_Help_HELP_Restore02p1_Text = " /b <RestoreName> [/v <VersionNumber>] [/e <BackupPassword>]"
  102. Const L_Help_HELP_Restore18_Text = "/v <VersionNumber> Specifies the version number of the backup."
  103. Const L_Help_HELP_Restore18p1_Text = " Can be any integer or HIGHEST_VERSION."
  104. Const L_Help_HELP_Restore19_Text = "/e <BackupPassword> If the backup was encrypted using a user specified"
  105. Const L_Help_HELP_Restore19p1_Text = " password, you must supply the correct password to"
  106. Const L_Help_HELP_Restore19p2_Text = " restore the backup."
  107. Const L_Help_HELP_Restore21_Text = "IIsBack /restore /b MyBackup /v HIGHEST_VERSION"
  108. Const L_Help_HELP_Restore22_Text = "IIsBack /s Server1 /u Administrator /p p@ssW0rd /restore /b MyBackup /v 2"
  109. ' Delete help messages
  110. Const L_Help_HELP_Delete01_Text = "Description: Delete an existing backup file."
  111. Const L_Help_HELP_Delete02_Text = "Syntax: IIsBack [/s <server> [/u <username> [/p <password>]]] /delete"
  112. Const L_Help_HELP_Delete02p1_Text = " /b <BackupName> /v <VersionNumber>"
  113. Const L_Help_HELP_Delete18_Text = "/v <VersionNumber> Specifies the version number to delete. Can be"
  114. Const L_Help_HELP_Delete18p1_Text = " integer or HIGHEST_VERSION."
  115. Const L_Help_HELP_Delete19_Text = "IIsBack /delete /b MyBackup /v HIGHEST_VERSION"
  116. Const L_Help_HELP_Delete20_Text = "IIsBack /s Server1 /u Administrator /p p@ssWOrd /delete /b MyBackup /v 2"
  117. ' List help messages
  118. Const L_Help_HELP_List01_Text = "Description: List all backup files."
  119. Const L_Help_HELP_List02_Text = "Syntax: IIsBack [/s <server> [/u <username> [/p <password>]]] /list"
  120. Const L_Help_HELP_List18_Text = "IIsBack /list"
  121. Const L_Help_HELP_List19_Text = "IIsBack /s Server1 /u Administrator /p p@ssW0rd /list"
  122. ''''''''''''''''''''''''
  123. ' Operation codes
  124. Const OPER_BACKUP = 1
  125. Const OPER_RESTORE = 2
  126. Const OPER_DELETE = 3
  127. Const OPER_LIST = 4
  128. ' Backup/Restore contants
  129. Const BACKUP_DEFAULT_NAME = "SampleBackup"
  130. Const MD_BACKUP_HIGHEST_VERSION = &HFFFFFFFE ' Backup, Restore, Delete
  131. Const MD_BACKUP_NEXT_VERSION = &HFFFFFFFF ' Backup
  132. Const MD_BACKUP_OVERWRITE = 1 ' Backup
  133. Const MD_BACKUP_SAVE_FIRST = 2 ' Backup
  134. Const MD_BACKUP_MAX_VERSION = 9999 ' Limit
  135. Const MD_BACKUP_MAX_LEN = 100 ' Limit
  136. Const MD_BACKUP_NO_MORE_BACKUPS = &H80070103 ' EnumBackups
  137. Const INVALID_VERSION = -3
  138. '
  139. ' Main block
  140. '
  141. Dim oScriptHelper, oCmdLib
  142. Dim strServer, strUser, strPassword
  143. Dim strName, strBackPassword
  144. Dim intOperation, intResult, intVersion
  145. Dim aArgs, arg
  146. Dim bOverwrite
  147. Dim strCmdLineOptions
  148. Dim oError
  149. ' Default values
  150. strServer = "."
  151. strUser = ""
  152. strPassword = ""
  153. intOperation = 0
  154. strName = "SampleBackup"
  155. strBackPassword = ""
  156. bOverwrite = False
  157. ' Instantiate script helper object
  158. Set oScriptHelper = CreateObject("Microsoft.IIsScriptHelper")
  159. If Err.Number <> 0 Then
  160. WScript.Echo L_ScriptHelper_ErrorMessage
  161. WScript.Echo L_ChkScpHelperReg_ErrorMessage
  162. WScript.Quit(ERR_GENERAL_FAILURE)
  163. End If
  164. Set oScriptHelper.ScriptHost = WScript
  165. ' Check if we are being run with cscript.exe instead of wscript.exe
  166. oScriptHelper.CheckScriptEngine
  167. ' Minimum number of parameters must exist
  168. If WScript.Arguments.Count < 1 Then
  169. WScript.Echo L_NotEnoughParams_ErrorMessage
  170. WScript.Echo L_SeeHelp_Message
  171. WScript.Quit(ERR_GENERAL_FAILURE)
  172. End If
  173. strCmdLineOptions = "[server:s:1;user:u:1;password:p:1];[backup::0;overwrite::0];restore::0;" & _
  174. "delete::0;list::0;backupname:b:1;version:v:1;bkpasswd:e:1"
  175. Set oError = oScriptHelper.ParseCmdLineOptions(strCmdLineOptions)
  176. If Not oError Is Nothing Then
  177. If oError.ErrorCode = oScriptHelper.ERROR_NOT_ENOUGH_ARGS Then
  178. ' Not enough arguments for a specified switch
  179. WScript.Echo L_NotEnoughParams_ErrorMessage
  180. WScript.Echo L_SeeHelp_Message
  181. Else
  182. ' Invalid switch
  183. WScript.Echo L_InvalidSwitch_ErrorMessage & oError.SwitchName
  184. WScript.Echo L_SeeHelp_Message
  185. End If
  186. WScript.Quit(ERR_GENERAL_FAILURE)
  187. End If
  188. If oScriptHelper.GlobalHelpRequested Then
  189. DisplayHelpMessage
  190. WScript.Quit(ERR_OK)
  191. End If
  192. For Each arg In oScriptHelper.Switches
  193. Select Case arg
  194. Case "server"
  195. ' Server information
  196. strServer = oScriptHelper.GetSwitch(arg)
  197. Case "user"
  198. ' User information
  199. strUser = oScriptHelper.GetSwitch(arg)
  200. Case "password"
  201. ' Password information
  202. strPassword = oScriptHelper.GetSwitch(arg)
  203. Case "backup"
  204. If (intOperation <> 0) Then
  205. WScript.Echo L_OnlyOneOper_ErrorMessage
  206. WScript.Echo L_SeeHelp_Message
  207. WScript.Quit(ERR_GENERAL_FAILURE)
  208. End If
  209. intOperation = OPER_BACKUP
  210. If oScriptHelper.IsHelpRequested(arg) Then
  211. DisplayBackupHelpMessage
  212. WScript.Quit(ERR_OK)
  213. End If
  214. strName = oScriptHelper.GetSwitch("backupname")
  215. If strName = "" Then
  216. strName = BACKUP_DEFAULT_NAME
  217. End If
  218. If oScriptHelper.Switches.Exists("version") Then
  219. intVersion = oScriptHelper.GetSwitch("version")
  220. Else
  221. intVersion = "NEXT_VERSION"
  222. End If
  223. strBackPassword = CStr(oScriptHelper.GetSwitch("bkpasswd"))
  224. If oScriptHelper.Switches.Exists("overwrite") Then
  225. bOverwrite = True
  226. End If
  227. Case "restore"
  228. If (intOperation <> 0) Then
  229. WScript.Echo L_OnlyOneOper_ErrorMessage
  230. WScript.Echo L_SeeHelp_Message
  231. WScript.Quit(ERR_GENERAL_FAILURE)
  232. End If
  233. intOperation = OPER_RESTORE
  234. If oScriptHelper.IsHelpRequested(arg) Then
  235. DisplayRestoreHelpMessage
  236. WScript.Quit(ERR_OK)
  237. End If
  238. strName = oScriptHelper.GetSwitch("backupname")
  239. If strName = "" Then
  240. WScript.Echo L_MinInfoNeeded_ErrorMessage
  241. WScript.Echo L_SeeRestoreHelp_Message
  242. WScript.Quit(ERR_GENERAL_FAILURE)
  243. End If
  244. If oScriptHelper.Switches.Exists("version") Then
  245. intVersion = oScriptHelper.GetSwitch("version")
  246. Else
  247. intVersion = "HIGHEST_VERSION"
  248. End If
  249. strBackPassword = CStr(oScriptHelper.GetSwitch("bkpasswd"))
  250. Case "delete"
  251. If (intOperation <> 0) Then
  252. WScript.Echo L_OnlyOneOper_ErrorMessage
  253. WScript.Echo L_SeeHelp_Message
  254. WScript.Quit(ERR_GENERAL_FAILURE)
  255. End If
  256. intOperation = OPER_DELETE
  257. If oScriptHelper.IsHelpRequested(arg) Then
  258. DisplayDeleteHelpMessage
  259. WScript.Quit(ERR_OK)
  260. End If
  261. strName = oScriptHelper.GetSwitch("backupname")
  262. If strName = "" Or Not oScriptHelper.Switches.Exists("version") Then
  263. WScript.Echo L_NeedNameVersion_ErrorMessage
  264. WScript.Echo L_SeeDeleteHelp_Message
  265. WScript.Quit(ERR_GENERAL_FAILURE)
  266. End If
  267. intVersion = oScriptHelper.GetSwitch("version")
  268. Case "list"
  269. If (intOperation <> 0) Then
  270. WScript.Echo L_OnlyOneOper_ErrorMessage
  271. WScript.Echo L_SeeHelp_Message
  272. WScript.Quit(ERR_GENERAL_FAILURE)
  273. End If
  274. intOperation = OPER_LIST
  275. If oScriptHelper.IsHelpRequested(arg) Then
  276. DisplayListHelpMessage
  277. WScript.Quit(ERR_OK)
  278. End If
  279. End Select
  280. Next
  281. ' Check Parameters
  282. If intOperation = 0 Then
  283. WScript.Echo L_OperationRequired_ErrorMessage
  284. WScript.Echo L_SeeHelp_Message
  285. WScript.Quit(ERR_GENERAL_FAILURE)
  286. End If
  287. ' Validate backup name
  288. ValidateBackupName strName
  289. If Err.Number Then
  290. WScript.Echo L_InvalidBackupName_ErrorMessage
  291. WScript.Quit(Err.Number)
  292. End If
  293. ' Validate version
  294. intVersion = ValidateVersionNumber(intVersion)
  295. If Err.Number Then
  296. Select Case Err.Number
  297. Case &H6
  298. WScript.Echo L_VersionTooBig_ErrorMessage
  299. Case &H5
  300. WScript.Echo L_InvalidVersion_ErrorMessage
  301. End Select
  302. WScript.Quit(Err.Number)
  303. End If
  304. ' Check if /p is specified but /u isn't. In this case, we should bail out with an error
  305. If oScriptHelper.Switches.Exists("password") And Not oScriptHelper.Switches.Exists("user") Then
  306. WScript.Echo L_PassWithoutUser_ErrorMessage
  307. WScript.Quit(ERR_GENERAL_FAILURE)
  308. End If
  309. ' Check if /u is specified but /p isn't. In this case, we should ask for a password
  310. If oScriptHelper.Switches.Exists("user") And Not oScriptHelper.Switches.Exists("password") Then
  311. Set oCmdLib = CreateObject("Microsoft.CmdLib")
  312. Set oCmdLib.ScriptingHost = WScript.Application
  313. If Err.Number Then
  314. WScript.Echo L_CmdLib_ErrorMessage
  315. WScript.Quit(Err.Number)
  316. Else
  317. strPassword = oCmdLib.GetPassword
  318. Set oCmdLib = Nothing
  319. End If
  320. End If
  321. ' Initializes authentication with remote machine
  322. intResult = oScriptHelper.InitAuthentication(strServer, strUser, strPassword)
  323. If intResult <> 0 Then
  324. WScript.Quit(intResult)
  325. End If
  326. ' Choose operation
  327. Select Case intOperation
  328. Case OPER_BACKUP
  329. intResult = BackupMetabase(strName, intVersion, strBackPassword, bOverwrite)
  330. Case OPER_RESTORE
  331. intResult = RestoreMetabase(strName, intVersion, strBackPassword)
  332. Case OPER_DELETE
  333. intResult = DeleteBackup(strName, intVersion)
  334. Case OPER_LIST
  335. intResult = ListBackups()
  336. End Select
  337. ' Return value to command processor
  338. WScript.Quit(intResult)
  339. '''''''''''''''''''''''''
  340. ' End Of Main Block
  341. '''''''''''''''''''''
  342. '''''''''''''''''''''''''''
  343. ' DisplayHelpMessage
  344. '''''''''''''''''''''''''''
  345. Sub DisplayHelpMessage()
  346. WScript.Echo L_Help_HELP_General01_Text
  347. WScript.Echo
  348. WScript.Echo L_Help_HELP_General02_Text
  349. WScript.Echo L_Help_HELP_General03_Text
  350. WScript.Echo
  351. WScript.Echo L_Help_HELP_General04_Text
  352. WScript.Echo
  353. WScript.Echo L_Help_HELP_General06_Text
  354. WScript.Echo L_Help_HELP_General07_Text
  355. WScript.Echo L_Help_HELP_General08_Text
  356. WScript.Echo L_Help_HELP_General09_Text
  357. WScript.Echo L_Help_HELP_General10_Text
  358. WScript.Echo L_Help_HELP_General11_Text
  359. WScript.Echo L_Help_HELP_General12_Text
  360. WScript.Echo L_Help_HELP_General13_Text
  361. WScript.Echo L_Help_HELP_General14_Text
  362. WScript.Echo L_Help_HELP_General15_Text
  363. WScript.Echo L_Help_HELP_General16_Text
  364. WScript.Echo
  365. WScript.Echo L_Help_HELP_General17_Text
  366. WScript.Echo
  367. WScript.Echo L_Help_HELP_General18_Text
  368. WScript.Echo L_Help_HELP_General19_Text
  369. WScript.Echo L_Help_HELP_General20_Text
  370. WScript.Echo L_Help_HELP_General21_Text
  371. End Sub
  372. Sub DisplayBackupHelpMessage()
  373. WScript.Echo L_Help_HELP_Backup01_Text
  374. WScript.Echo
  375. WScript.Echo L_Help_HELP_Backup02_Text
  376. WScript.Echo L_Help_HELP_Backup02p1_Text
  377. WScript.Echo L_Help_HELP_Backup02p2_Text
  378. WScript.Echo
  379. WScript.Echo L_Help_HELP_General04_Text
  380. WScript.Echo
  381. WScript.Echo L_Help_HELP_General06_Text
  382. WScript.Echo L_Help_HELP_General07_Text
  383. WScript.Echo L_Help_HELP_General08_Text
  384. WScript.Echo L_Help_HELP_General09_Text
  385. WScript.Echo L_Help_HELP_General10_Text
  386. WScript.Echo L_Help_HELP_Common17_Text
  387. WScript.Echo L_Help_HELP_Common17p1_Text
  388. WScript.Echo L_Help_HELP_Backup18_Text
  389. WScript.Echo L_Help_HELP_Backup18p1_Text
  390. WScript.Echo L_Help_HELP_Backup18p2_Text
  391. WScript.Echo L_Help_HELP_Backup19_Text
  392. 'WScript.Echo L_Help_HELP_Backup19p1_Text
  393. WScript.Echo L_Help_HELP_Backup20_Text
  394. WScript.Echo L_Help_HELP_Backup20p1_Text
  395. WScript.Echo L_Help_HELP_Backup20p2_Text
  396. WScript.Echo
  397. WScript.Echo L_Help_HELP_Common11_Text
  398. WScript.Echo
  399. WScript.Echo L_Help_HELP_Backup21_Text
  400. WScript.Echo L_Help_HELP_Backup22_Text
  401. End Sub
  402. Sub DisplayRestoreHelpMessage()
  403. WScript.Echo L_Help_HELP_Restore01_Text
  404. WScript.Echo L_Help_HELP_Restore01p1_Text
  405. WScript.Echo
  406. WScript.Echo L_Help_HELP_Restore02_Text
  407. WScript.Echo L_Help_HELP_Restore02p1_Text
  408. WScript.Echo
  409. WScript.Echo L_Help_HELP_General04_Text
  410. WScript.Echo
  411. WScript.Echo L_Help_HELP_General06_Text
  412. WScript.Echo L_Help_HELP_General07_Text
  413. WScript.Echo L_Help_HELP_General08_Text
  414. WScript.Echo L_Help_HELP_General09_Text
  415. WScript.Echo L_Help_HELP_General10_Text
  416. WScript.Echo L_Help_HELP_Common17_Text
  417. WScript.Echo L_Help_HELP_Common17p1_Text
  418. WScript.Echo L_Help_HELP_Restore18_Text
  419. WScript.Echo L_Help_HELP_Restore18p1_Text
  420. WScript.Echo L_Help_HELP_Restore19_Text
  421. WScript.Echo L_Help_HELP_Restore19p1_Text
  422. WScript.Echo L_Help_HELP_Restore19p2_Text
  423. WScript.Echo
  424. WScript.Echo L_Help_HELP_Common11_Text
  425. WScript.Echo
  426. WScript.Echo L_Help_HELP_Restore21_Text
  427. WScript.Echo L_Help_HELP_Restore22_Text
  428. End Sub
  429. Sub DisplayDeleteHelpMessage()
  430. WScript.Echo L_Help_HELP_Delete01_Text
  431. WScript.Echo
  432. WScript.Echo L_Help_HELP_Delete02_Text
  433. WScript.Echo L_Help_HELP_Delete02p1_Text
  434. WScript.Echo
  435. WScript.Echo L_Help_HELP_General04_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_Common17_Text
  443. WScript.Echo L_Help_HELP_Common17p1_Text
  444. WScript.Echo L_Help_HELP_Delete18_Text
  445. WScript.Echo L_Help_HELP_Delete18p1_Text
  446. WScript.Echo
  447. WScript.Echo L_Help_HELP_Common11_Text
  448. WScript.Echo
  449. WScript.Echo L_Help_HELP_Delete19_Text
  450. WScript.Echo L_Help_HELP_Delete20_Text
  451. End Sub
  452. Sub DisplayListHelpMessage()
  453. WScript.Echo L_Help_HELP_List01_Text
  454. WScript.Echo
  455. WScript.Echo L_Help_HELP_List02_Text
  456. WScript.Echo
  457. WScript.Echo L_Help_HELP_General04_Text
  458. WScript.Echo
  459. WScript.Echo L_Help_HELP_General06_Text
  460. WScript.Echo L_Help_HELP_General07_Text
  461. WScript.Echo L_Help_HELP_General08_Text
  462. WScript.Echo L_Help_HELP_General09_Text
  463. WScript.Echo L_Help_HELP_General10_Text
  464. WScript.Echo
  465. WScript.Echo L_Help_HELP_Common11_Text
  466. WScript.Echo
  467. WScript.Echo L_Help_HELP_List18_Text
  468. WScript.Echo L_Help_HELP_List19_Text
  469. End Sub
  470. '''''''''''''''''''''''''''
  471. ' BackupMetabase
  472. '''''''''''''''''''''''''''
  473. Function BackupMetabase(strName, intVersion, strBackPassword, bOverwrite)
  474. Dim ComputerObj
  475. Dim intFlags
  476. Dim strVersion
  477. On Error Resume Next
  478. oScriptHelper.WMIConnect
  479. If Err Then
  480. WScript.Echo L_WMIConnect_ErrorMessage
  481. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  482. BackupMetabase = Err.Number
  483. Exit Function
  484. End If
  485. ' Grab the computer object
  486. Set ComputerObj = oScriptHelper.ProviderObj.Get("IIsComputer='LM'")
  487. If Err Then
  488. WScript.Echo L_ComputerObj_ErrorMessage
  489. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  490. BackupMetabase = Err.Number
  491. Exit Function
  492. End If
  493. ' Build backup flags
  494. intFlags = MD_BACKUP_SAVE_FIRST
  495. If bOverwrite Then
  496. intFlags = intFlags Or MD_BACKUP_OVERWRITE
  497. End If
  498. ' Call Backup method
  499. ComputerObj.BackupWithPassword strName, intVersion, intFlags, strBackPassword
  500. If Err.Number Then
  501. Select Case Err.Number
  502. Case &H80070002
  503. WScript.Echo L_BackupNotFound_ErrorMessage
  504. Case &H80070050
  505. WScript.Echo L_BackupExists_ErrorMessage
  506. Case Else
  507. WScript.Echo L_Backup_ErrorMessage
  508. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  509. End Select
  510. BackupMetabase = Err.Number
  511. Exit Function
  512. End If
  513. ' Pretty print
  514. If (intVersion = MD_BACKUP_NEXT_VERSION) Then
  515. strVersion = "NEXT_VERSION"
  516. Else
  517. If (intVersion = MD_BACKUP_HIGHEST_VERSION) Then
  518. strVersion = "HIGHEST_VERSION"
  519. Else
  520. strVersion = CStr(intVersion)
  521. End If
  522. End If
  523. WScript.Echo L_Backup_Text & " " & strName & " " & L_Version_Text & " " & strVersion & " " & _
  524. L_HasBeen_Message & " " & L_Created_Text & "."
  525. ' Release object
  526. Set ComputerObj = Nothing
  527. BackupMetabase = 0
  528. End Function
  529. '''''''''''''''''''''''''''
  530. ' RestoreMetabase
  531. '''''''''''''''''''''''''''
  532. Function RestoreMetabase(strName, intVersion, strBackPassword)
  533. Dim ComputerObj
  534. Dim strVersion
  535. On Error Resume Next
  536. oScriptHelper.WMIConnect
  537. If Err Then
  538. WScript.Echo L_WMIConnect_ErrorMessage
  539. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  540. RestoreMetabase = Err.Number
  541. Exit Function
  542. End If
  543. ' Grab the computer object
  544. Set ComputerObj = oScriptHelper.ProviderObj.Get("IIsComputer='LM'")
  545. If Err Then
  546. WScript.Echo L_ComputerObj_ErrorMessage
  547. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  548. RestoreMetabase = Err.Number
  549. Exit Function
  550. End If
  551. ' Call Restore method
  552. ComputerObj.RestoreWithPassword strName, intVersion, 0, strBackPassword
  553. If Err.Number Then
  554. Select Case Err.Number
  555. Case &H8007052B
  556. WScript.Echo L_IncorrectPassword_ErrorMessage
  557. Case Else
  558. WScript.Echo L_Restore_ErrorMessage
  559. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  560. End Select
  561. RestoreMetabase = Err.Number
  562. Exit Function
  563. End If
  564. ' Pretty print
  565. If (intVersion = MD_BACKUP_NEXT_VERSION) Then
  566. strVersion = "NEXT_VERSION"
  567. Else
  568. If (intVersion = MD_BACKUP_HIGHEST_VERSION) Then
  569. strVersion = "HIGHEST_VERSION"
  570. Else
  571. strVersion = CStr(intVersion)
  572. End If
  573. End If
  574. WScript.Echo L_Backup_Text & " " & strName & " " & L_Version_Text & " " & strVersion & " " & _
  575. L_HasBeen_Message & " " & L_Restored_Text & "."
  576. ' Release object
  577. Set ComputerObj = Nothing
  578. RestoreMetabase = 0
  579. End Function
  580. '''''''''''''''''''''''''''
  581. ' DeleteBackup
  582. '''''''''''''''''''''''''''
  583. Function DeleteBackup(strName, intVersion)
  584. Dim ComputerObj
  585. Dim strVersion
  586. On Error Resume Next
  587. oScriptHelper.WMIConnect
  588. If Err Then
  589. WScript.Echo L_WMIConnect_ErrorMessage
  590. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  591. DeleteMetabase = Err.Number
  592. Exit Function
  593. End If
  594. ' Grab the computer object
  595. Set ComputerObj = oScriptHelper.ProviderObj.Get("IIsComputer='LM'")
  596. If Err Then
  597. WScript.Echo L_ComputerObj_ErrorMessage
  598. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  599. DeleteBackup = Err.Number
  600. Exit Function
  601. End If
  602. ' Call Delete method
  603. ComputerObj.DeleteBackup strName, intVersion
  604. If Err Then
  605. WScript.Echo L_Delete_ErrorMessage
  606. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  607. DeleteBackup = Err.Number
  608. Exit Function
  609. End If
  610. ' Pretty print
  611. If (intVersion = MD_BACKUP_NEXT_VERSION) Then
  612. strVersion = "NEXT_VERSION"
  613. Else
  614. If (intVersion = MD_BACKUP_HIGHEST_VERSION) Then
  615. strVersion = "HIGHEST_VERSION"
  616. Else
  617. strVersion = CStr(intVersion)
  618. End If
  619. End If
  620. WScript.Echo L_Backup_Text & " " & strName & " " & L_Version_Text & " " & strVersion & " " & _
  621. L_HasBeen_Message & " " & L_Deleted_Text & "."
  622. ' Release object
  623. Set ComputerObj = Nothing
  624. DeleteBackup = 0
  625. End Function
  626. '''''''''''''''''''''''''''
  627. ' ListBackups
  628. '''''''''''''''''''''''''''
  629. Function ListBackups()
  630. Dim ComputerObj
  631. Dim strName, strVersion, strDateTime, strFmtDateTime
  632. Dim dtDate, dtTime
  633. Dim intIndex
  634. On Error Resume Next
  635. oScriptHelper.WMIConnect
  636. If Err.Number Then
  637. WScript.Echo L_WMIConnect_ErrorMessage
  638. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  639. ListBackups = Err.Number
  640. Exit Function
  641. End If
  642. ' Grab the computer object
  643. Set ComputerObj = oScriptHelper.ProviderObj.Get("IIsComputer='LM'")
  644. If (Err.Number <> 0) Then
  645. WScript.Echo L_ComputerObj_ErrorMessage
  646. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  647. ListBackups = ERR_GENERAL_FAILURE
  648. Exit Function
  649. End If
  650. intIndex = 0
  651. Do While True
  652. ' Call EnumBackups method
  653. strName = ""
  654. computerObj.EnumBackups strName, intIndex, strVersion, strDateTime
  655. If (Err.Number <> 0) Then
  656. If (Err.Number = MD_BACKUP_NO_MORE_BACKUPS) Then
  657. Exit Do
  658. End If
  659. WScript.Echo L_List_ErrorMessage
  660. WScript.Echo L_Error_ErrorMessage & " &H" & Hex(Err.Number) & ": " & Err.Description
  661. Set computerObj = Nothing
  662. ListBackups = ERR_GENERAL_FAILURE
  663. Exit Function
  664. End If
  665. If intIndex = 0 Then
  666. WScript.Echo L_BackupName_Text & Space(35 - Len(L_BackupName_Text)) & L_BackupVersion_Text & _
  667. Space(15 - Len(L_BackupVersion_Text)) & L_DateTime_Text
  668. WScript.Echo "========================================================================"
  669. End If
  670. ' Format DateTime
  671. dtDate = DateSerial(Mid(strDateTime, 1, 4), Mid(strDateTime, 5, 2), Mid(strDateTime, 7, 2))
  672. dtTime = TimeSerial(Mid(strDateTime, 9, 2), Mid(strDateTime, 11, 2), Mid(strDateTime, 13, 2))
  673. strFmtDateTime = FormatDateTime(dtDate) & " " & FormatDateTime(dtTime, vbLongTime)
  674. WScript.Echo strName & Space(35 - Len(strName)) & strVersion & Space(15 - Len(strVersion)) & strFmtDateTime
  675. intIndex = intIndex + 1
  676. Loop
  677. ' Print message in case we don't have any backups to list
  678. If intIndex = 0 Then
  679. WScript.Echo L_NoBackups_Message
  680. End If
  681. ' Release object
  682. Set ComputerObj = Nothing
  683. ListBackups = 0
  684. End Function
  685. ''''''''''''''''''''''''''''''''''''
  686. ' Helper Functions
  687. '''''''''''''''''''''''''''
  688. Function ValidateVersionNumber(Version)
  689. If IsNumeric(Version) Then
  690. Version = CInt(Version)
  691. If Version > MD_BACKUP_MAX_VERSION Then
  692. Err.Raise &H6
  693. End If
  694. If Version < 0 Then
  695. Err.Raise &H5
  696. End If
  697. ValidateVersionNumber = Version
  698. Else
  699. Select Case Version
  700. Case "HIGHEST_VERSION"
  701. ValidateVersionNumber = MD_BACKUP_HIGHEST_VERSION
  702. Case "NEXT_VERSION"
  703. ValidateVersionNumber = MD_BACKUP_NEXT_VERSION
  704. Case Else
  705. Err.Raise &H5
  706. End Select
  707. End If
  708. End Function
  709. Sub ValidateBackupName(strName)
  710. Dim i
  711. For i = 1 to Len(strName)
  712. If Asc(Mid(strName, i, 1)) >= 33 And Asc(Mid(strName, i, 1)) <= 47 Or _
  713. Asc(Mid(strName, i, 1)) >= 58 And Asc(Mid(strName, i, 1)) <= 64 Or _
  714. Asc(Mid(strName, i, 1)) > 122 Then
  715. Err.Raise &H5
  716. End If
  717. Next
  718. End Sub