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.

155 lines
4.0 KiB

  1. '''''''''''''''''''''''''''''''''''''''''''''
  2. '
  3. ' Document Footer Utility
  4. '
  5. '''''''''''''''''''''''''''''''''''''''''''''
  6. ' Description:
  7. ' ------------
  8. ' This sample admin script allows you to configure document footers.
  9. '
  10. ' To Run:
  11. ' -------
  12. ' This is the format for this script:
  13. '
  14. ' cscript metaback.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, InputError, FootEnabled, FootDoc, FootPath, ThisObj, EnableModify, ClearFlag
  24. ' Default values
  25. ArgCount = 0
  26. FootPath = "" ' This MUST be set by user via command-line
  27. FootDoc = ""
  28. FootEnabled = False
  29. EnableModify = False
  30. ClearFlag = False
  31. ' ** Parse Command Line
  32. ' Loop through arguments
  33. While ArgCount < Wscript.Arguments.Count
  34. ' Determine switches used
  35. Select Case Wscript.Arguments(ArgCount)
  36. Case "-s": ' Sets default footer explicitly to string
  37. ' Move to next arg, which should be parameter
  38. ArgCount = ArgCount + 1
  39. If ArgCount => Wscript.Arguments.Count Then
  40. Call UsageMsg
  41. Else
  42. FootDoc = "STRING:" & Wscript.Arguments(ArgCount)
  43. End If
  44. Case "-f": ' Sets default footer to a file
  45. ' Move to next arg, which should be parameter
  46. ArgCount = ArgCount + 1
  47. If ArgCount => Wscript.Arguments.Count Then
  48. Call UsageMsg
  49. Else
  50. FootDoc = "FILE:" & Wscript.Arguments(ArgCount)
  51. End If
  52. Case "+d": ' Enables doc footers
  53. FootEnabled = True
  54. EnableModify = True
  55. Case "-d": ' Disables doc footers
  56. FootEnabled = False
  57. EnableModify = True
  58. Case "-c": ' Clears all document footer settings from node
  59. ClearFlag = True
  60. Case "-h": ' Help!
  61. UsageMsg
  62. Case Else: ' ADsPath, we hope
  63. If FootPath <> "" Then ' Only one name allowed
  64. Call UsageMsg
  65. Else
  66. FootPath = Wscript.Arguments(ArgCount)
  67. End If
  68. End Select
  69. ' Move pointer to next argument
  70. ArgCount = ArgCount + 1
  71. Wend
  72. ' Quick screen to make sure input is valid
  73. If FootPath = "" Then
  74. Call UsageMsg
  75. End If
  76. ' **Perform Backup:
  77. ' First, create instance of ADSI object
  78. Set ADSIObj = GetObject(FootPath)
  79. ' Error getting that object?
  80. If Err.Number <> 0 Then
  81. Wscript.Echo "Error getting object at path " & FootPath & "."
  82. Wscript.Quit
  83. End If
  84. ' If no changes, then simply display current settings
  85. If (EnableModify = False) And (FootDoc = "") And (ClearFlag = False) Then ' Display current status
  86. If ADSIObj.EnableDocFooter = True Then
  87. Wscript.Echo FootPath & ": Footers currently enabled, value = " & ADSIObj.DefaultDocFooter
  88. Else
  89. Wscript.Echo FootPath & ": Footers currently disabled, value = " & ADSIObj.DefaultDocFooter
  90. End If
  91. Wscript.Quit
  92. End If
  93. ' Change settings for node
  94. If ClearFlag = True Then
  95. ADSIObj.EnableDocFooter = False
  96. ADSIObj.DefaultDocFooter = ""
  97. Else
  98. If EnableModify Then ADSIObj.EnableDocFooter = FootEnabled
  99. If FootDoc <> "" Then ADSIObj.DefaultDocFooter = FootDoc
  100. End If
  101. ' Save new settings back to node
  102. ADSIObj.SetInfo
  103. ' Error saving info to object?
  104. If Err.Number <> 0 Then
  105. Wscript.Echo "Error setting document footer info for path " & FootPath & "."
  106. Wscript.Quit
  107. End If
  108. ' Display results
  109. If ADSIObj.EnableDocFooter = True Then
  110. Wscript.Echo FootPath & ": Document footers enabled, value = " & ADSIObj.DefaultDocFooter
  111. Else
  112. Wscript.Echo FootPath & ": Document footers disabled, value = " & ADSIObj.DefaultDocFooter
  113. End If
  114. ' Displays usage message, then QUITS
  115. Sub UsageMsg
  116. Wscript.Echo "Usage: cscript dfoot.vbs <ADsPath> [+d|-d footers enabled] [[-s <string>] | [-f <filename>]]"
  117. Wscript.Quit
  118. End Sub