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.

153 lines
3.9 KiB

  1. /*********************************************
  2. *
  3. * Web Server Creation Utility
  4. *
  5. **********************************************
  6. *
  7. * Description:
  8. * ------------
  9. * This sample admin script allows you to create a web server.
  10. *
  11. * To Run:
  12. * -------
  13. * This is the format for this script:
  14. *
  15. * cscript mkwebsrv.js <rootdir> [-n <instancenum>][-c <comment>][-p <portnum>][-X (don't start)]
  16. *
  17. * NOTE: If you want to execute this script directly from Windows, use
  18. * 'wscript' instead of 'cscript'.
  19. *
  20. **********************************************/
  21. // Initialize variables
  22. var ArgCount, WRoot, WNumber, WComment, WPort, BindingsList, ServerRun;
  23. var ServiceObj, ServerObj, VDirObj;
  24. // Default values
  25. ArgCount = 0;
  26. WRoot = "";
  27. WNumber = 10;
  28. WComment = "SampleServer";
  29. WPort = new Array(":84:"); // default port; NOTE: takes an array of strings
  30. ServerRun = true;
  31. // ** Parse Command Line
  32. // Loop through arguments
  33. while (ArgCount < WScript.arguments.length) {
  34. // Determine switches used
  35. switch (WScript.arguments.item(ArgCount)) {
  36. case "-n": // Set server instance number
  37. // Move to next arg, which should be parameter
  38. ++ArgCount;
  39. if (ArgCount >= WScript.arguments.length)
  40. UsageMsg();
  41. else
  42. WNumber = WScript.arguments.item(ArgCount);
  43. break;
  44. case "-c": // Set server comment (friendly name)
  45. // Move to next arg, which should be parameter
  46. ++ArgCount;
  47. if (ArgCount >= WScript.arguments.length)
  48. UsageMsg();
  49. else
  50. WComment = WScript.arguments.item(ArgCount);
  51. break;
  52. case "-p": // Port binding
  53. // Move to next arg, which should be parameter
  54. ++ArgCount;
  55. if (ArgCount >= WScript.arguments.length)
  56. UsageMsg();
  57. else
  58. WPort[0] = ":" + WScript.arguments.item(ArgCount) + ":";
  59. break;
  60. case "-X": // Do NOT start the server upon creation
  61. ServerRun = false;
  62. break;
  63. case "-h": // Help!
  64. case "-?":
  65. case "/?":
  66. UsageMsg();
  67. break;
  68. default:
  69. if (WRoot != "") // Only one root allowed
  70. UsageMsg();
  71. else
  72. WRoot = WScript.arguments.item(ArgCount);
  73. }
  74. // Move pointer to next argument
  75. ++ArgCount;
  76. } // ** END command-line parse
  77. // Screen to make sure WRoot was set
  78. if (WRoot == "")
  79. UsageMsg();
  80. // ** Create Server **
  81. // First, create instance of Web service
  82. ServiceObj = GetObject("IIS://Localhost/W3SVC");
  83. // Second, create a new virtual server at the service
  84. ServerObj = ServiceObj.Create("IIsWebServer", WNumber);
  85. // Next, configure new server
  86. ServerObj.ServerSize = 1 // Medium-sized server;
  87. ServerObj.ServerComment = WComment;
  88. ServerObj.ServerBindings = WPort;
  89. // Write info back to Metabase
  90. ServerObj.SetInfo();
  91. // ** Create virtual root directory **
  92. VDirObj = ServerObj.Create("IIsWebVirtualDir", "ROOT");
  93. // Configure new virtual root
  94. VDirObj.Path = WRoot;
  95. VDirObj.AccessRead = true;
  96. VDirObj.AccessWrite = true;
  97. VDirObj.EnableDirBrowsing = true;
  98. // Write info back to Metabase
  99. VDirObj.SetInfo();
  100. // Success!
  101. WScript.echo("Created: Web server '" + WComment + "' (Physical root=" + WRoot + ", Port=" + WPort[0] + ").");
  102. // Start new server?
  103. if (ServerRun == true) {
  104. // Start server
  105. ServerObj.Start();
  106. WScript.echo("Started: Web server '" + WComment + "' (Physical root=" + WRoot + ", Port=" + WPort[0] + ").");
  107. }
  108. WScript.quit(0);
  109. // Displays usage message, then QUITS
  110. function UsageMsg() {
  111. WScript.echo("Usage: cscript mkwebsrv.js <rootdir> [-n <instancenum>][-c <comment>][-p <portnum>][-X (don't start)]");
  112. WScript.quit();
  113. }