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.

119 lines
3.0 KiB

  1. /*********************************************
  2. *
  3. * Filter Registration Utility
  4. *
  5. **********************************************
  6. *
  7. * Description:
  8. * ------------
  9. * This sample admin script allows you to install a new ISAPI filter on the server or
  10. * the service.
  11. *
  12. * To Run:
  13. * -------
  14. * This is the format for this script:
  15. *
  16. * cscript regfilt.js <filterpath> [-n <filtername>]
  17. *
  18. * NOTE: If you want to execute this script directly from Windows, use
  19. * 'wscript' instead of 'cscript'.
  20. *
  21. **********************************************/
  22. // Initialize variables
  23. var ArgCount, FName, FPath, FiltersObj, FilterObj, FullPath, LoadOrder;
  24. // Default values
  25. ArgCount = 0;
  26. FName = ""; // Name of filter
  27. FPath = ""; // Path to filter DLL
  28. // ** Parse Command Line
  29. // Loop through arguments
  30. while (ArgCount < WScript.arguments.length) {
  31. // Determine switches used
  32. switch (WScript.arguments.item(ArgCount)) {
  33. case "-n": // Name of filter
  34. // Move to next arg, which should be parameter
  35. ++ArgCount;
  36. if (ArgCount >= WScript.arguments.length)
  37. UsageMsg();
  38. else
  39. FName = WScript.arguments.item(ArgCount);
  40. break;
  41. case "-h": // Help!
  42. case "-?":
  43. case "/?":
  44. UsageMsg();
  45. break;
  46. default:
  47. if (FPath != "") // Only one name allowed
  48. UsageMsg();
  49. else
  50. FPath = WScript.arguments.item(ArgCount);
  51. }
  52. // Move pointer to next argument
  53. ++ArgCount;
  54. }
  55. // Path to DLL filter must be provided
  56. if (FPath == "")
  57. UsageMsg();
  58. // Set filter name to path, if none provided
  59. if (FName == "")
  60. FName == FPath;
  61. // Access ADSI object for the IIsFilters object
  62. // NOTE: If you wish to add a filter at the server level, you will have to check
  63. // the IIsServer object for an IIsFilters node. If such a node does not exist, it will
  64. // need to be created using Create().
  65. FiltersObj = GetObject("IIS://Localhost/W3SVC/Filters");
  66. // Create and configure new IIsFilter object
  67. FilterObj = FiltersObj.Create("IIsFilter", FName);
  68. FilterObj.FilterPath = FPath;
  69. // Write info back to Metabase
  70. FilterObj.SetInfo();
  71. // Modify FilterLoadOrder, to include to new filter
  72. LoadOrder = FiltersObj.FilterLoadOrder;
  73. if (LoadOrder != "")
  74. LoadOrder = LoadOrder + ",";
  75. // Add new filter to end of load order list
  76. LoadOrder = LoadOrder + FName;
  77. FiltersObj.FilterLoadOrder = LoadOrder;
  78. // Write changes back to Metabase
  79. FiltersObj.SetInfo();
  80. WScript.echo("Filter '" + FName + "' (path " + FPath + ") has been successfully registered.");
  81. WScript.quit(0);
  82. // Displays usage message, then QUITS
  83. function UsageMsg() {
  84. WScript.echo("Usage: cscript regfilt.js <filterpath> [-n <filtername>] ");
  85. WScript.quit();
  86. }