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.

112 lines
2.7 KiB

  1. '''''''''''''''''''''''''''''''''''''''''''''
  2. '
  3. ' Metabase Backup Deletion Utility
  4. '
  5. '''''''''''''''''''''''''''''''''''''''''''''
  6. ' Description:
  7. ' ------------
  8. ' This sample admin script allows you to delete a Metabase backup.
  9. '
  10. ' To Run:
  11. ' -------
  12. ' This is the format for this script:
  13. '
  14. ' cscript metabackdel.vbs
  15. '
  16. ' NOTE: If you want to execute this script directly from Windows, use
  17. ' 'wscript' instead of 'cscript'.
  18. '
  19. '''''''''''''''''''''''''''''''''''''''''''''
  20. ' Initialize error checking
  21. On Error Resume Next
  22. ' Initialize variables
  23. Dim ArgCount, BuName, BuVersion, CompObj, VersionMsg
  24. ' Default values
  25. ArgCount = 0
  26. BuName = "" ' Default backup, but will not be allowed
  27. BuVersion = &HFFFFFFFE ' Designates highest existing version
  28. ' ** Parse Command Line
  29. ' Loop through arguments
  30. While ArgCount < Wscript.Arguments.Count
  31. ' Determine switches used
  32. Select Case Wscript.Arguments(ArgCount)
  33. Case "-v": ' Designate backup version to be deleted
  34. ' Move to next arg, which should be parameter
  35. ArgCount = ArgCount + 1
  36. If ArgCount => Wscript.Arguments.Count Then
  37. Call UsageMsg
  38. Else
  39. BuVersion = Wscript.Arguments(ArgCount)
  40. End If
  41. Case "-h", "/?", "-?":
  42. Call UsageMsg
  43. Case Else:
  44. If BuName <> "" Then ' Only one name allowed
  45. Call UsageMsg
  46. Else
  47. BuName = Wscript.Arguments(ArgCount)
  48. End If
  49. End Select
  50. ' Move pointer to next argument
  51. ArgCount = ArgCount + 1
  52. Wend
  53. ' If no location name was selected, generate error
  54. If BuName = "" Then
  55. Call UsageMsg
  56. End If
  57. ' Get instance of computer object
  58. Set CompObj = GetObject("IIS://Localhost")
  59. ' Try to delete backup
  60. CompObj.DeleteBackup BuName, BuVersion
  61. ' Make version string pretty
  62. If BuVersion = &HFFFFFFFE Then
  63. VersionMsg = "highest version"
  64. Else
  65. VersionMsg = "version " & BuVersion
  66. End If
  67. If Err.Number <> 0 Then ' Errors!
  68. If Err.Number = &H80070002 Then ' Version doesn't exist
  69. Wscript.Echo "Error deleting backup: '" & BuName & "' (" & VersionMsg & ") does not exist."
  70. Else ' Some other error
  71. Wscript.Echo "Error deleting backup: '" & BuName & "' (" & VersionMsg & ")."
  72. Wscript.Echo "Error number: " & Hex(Err.Number)
  73. End If
  74. Else ' No errors!
  75. Wscript.Echo "Backup deleted: '" & BuName & "' (" & VersionMsg & ")."
  76. End If
  77. ' Displays usage message, then QUITS
  78. Sub UsageMsg
  79. Wscript.Echo "Usage: cscript metabackdel.vbs <backupname> [-v <versionnum>]"
  80. Wscript.Quit
  81. End Sub