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.

146 lines
3.7 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.js
  15. *
  16. * NOTE: If you want to execute this script directly from Windows, use
  17. * 'wscript' instead of 'cscript'.
  18. *
  19. **********************************************/
  20. // Initialize variables
  21. var ArgCount, InputError, FootEnabled, FootDoc, FootPath, ThisObj, EnableModify, ClearFlag;
  22. // Default values
  23. ArgCount = 0;
  24. FootPath = ""; // This MUST be set by user via command-line
  25. FootDoc = "";
  26. FootEnabled = false;
  27. EnableModify = false;
  28. ClearFlag = false;
  29. // ** Parse Command Line
  30. // Loop through arguments
  31. while (ArgCount < WScript.arguments.length) {
  32. // Determine switches used
  33. switch (WScript.arguments.item(ArgCount)) {
  34. case "-s": // Sets default footer explicitly to string
  35. // Move to next arg, which should be parameter
  36. ++ArgCount;
  37. if (ArgCount >= WScript.arguments.length)
  38. UsageMsg();
  39. else
  40. FootDoc = "STRING:" + WScript.arguments.item(ArgCount);
  41. break;
  42. case "-f": // Sets default footer to a file
  43. // Move to next arg, which should be parameter
  44. ++ArgCount;
  45. if (ArgCount >= WScript.arguments.length)
  46. UsageMsg();
  47. else
  48. FootDoc = "FILE:" + WScript.arguments.item(ArgCount);
  49. break;
  50. case "+d": // Enables doc footers
  51. FootEnabled = true;
  52. EnableModify = true;
  53. break;
  54. case "-d": // Disables doc footers
  55. FootEnabled = false;
  56. EnableModify = true;
  57. break;
  58. case "-c": // Clears all document footer settings from node
  59. ClearFlag = true;
  60. break;
  61. case "-h": // Help!
  62. UsageMsg();
  63. break;
  64. default: // ADsPath, we hope
  65. if (FootPath != "") // Only one name allowed
  66. UsageMsg();
  67. else
  68. FootPath = WScript.arguments.item(ArgCount);
  69. }
  70. // Move pointer to next argument
  71. ++ArgCount;
  72. }
  73. // Quick screen to make sure input is valid
  74. if (FootPath == "")
  75. UsageMsg();
  76. // **Perform Backup:
  77. // First, create instance of ADSI object
  78. ADSIObj = GetObject(FootPath);
  79. // If no changes, then simply display current settings
  80. if ( (!EnableModify) && (FootDoc == "") && (!ClearFlag) ) {
  81. if (ADSIObj.EnableDocFooter == true)
  82. WScript.echo(FootPath + ": Footers currently enabled, value = " + ADSIObj.DefaultDocFooter);
  83. else
  84. WScript.echo(FootPath + ": Footers currently disabled, value = " + ADSIObj.DefaultDocFooter);
  85. WScript.quit();
  86. }
  87. // Otherwise, perform changes
  88. if (ClearFlag) {
  89. ADSIObj.EnableDocFooter = false;
  90. ADSIObj.DefaultDocFooter = "";
  91. }
  92. else {
  93. if (EnableModify)
  94. ADSIObj.EnableDocFooter = FootEnabled;
  95. if (FootDoc != "")
  96. ADSIObj.DefaultDocFooter = FootDoc ;
  97. }
  98. // Save new settings back to Metabase
  99. ADSIObj.SetInfo();
  100. // Display results
  101. if (ADSIObj.EnableDocFooter)
  102. WScript.echo(FootPath + ": Document footers enabled, value = " + ADSIObj.DefaultDocFooter);
  103. else
  104. WScript.echo(FootPath + ": Document footers disabled, value = " + ADSIObj.DefaultDocFooter);
  105. // Displays usage message, then QUITS
  106. function UsageMsg() {
  107. WScript.echo("Usage: cscript dfoot.js <ADsPath> [+d|-d footers enabled] [[-s <string>] | [-f <filename>]] [-c to clear]");
  108. WScript.quit();
  109. }