Leaked source code of windows server 2003
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.

148 lines
3.7 KiB

  1. //-------------------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation, 2002
  3. //
  4. // bitsremv.js
  5. //
  6. // Executed when the BITS Server Extension is uninstalled in order to
  7. // find and disable all IIS Virtual Directories which have BITS upload
  8. // enabled.
  9. //
  10. //-------------------------------------------------------------------------
  11. //-------------------------------------------------------------------------
  12. // Start of localization content
  13. //-------------------------------------------------------------------------
  14. // Script useage help text:
  15. L_Help1 = "bitsremv.js [/disable]";
  16. L_Help2 = " /disable If specified then disable BITS Server Extension for all virtual";
  17. L_Help3 = " directories where it is currently enabled. If not specified, then";
  18. L_Help4 = " only list all virtual directories where BITS is currently enabled.";
  19. L_Help5 = "";
  20. L_Help6 = "";
  21. // Text when listing/disabling vdirs:
  22. L_NoBitsDirectories = "No virtual directories currently have the BITS Server Extension enabled."
  23. L_ListTitle = "BITS Enabled Virtual Directories";
  24. L_DisableTitle = "Disable BITS Server Extension on Virtual Directories";
  25. L_Enabled = "Enabled: ";
  26. L_Disabled = "Disabled: ";
  27. L_Disabling = "Disabling:";
  28. L_TotalCount = "Number of Directories where BITS was enabled: ";
  29. L_FailedConnectToIIS= "Failed to connect and query IIS for virtual directories.";
  30. L_FailedToDisable = "Failed to disable the virtual directory.";
  31. //-------------------------------------------------------------------------
  32. // End of localization content
  33. //-------------------------------------------------------------------------
  34. function PrintHelp()
  35. {
  36. WScript.Echo(L_Help1);
  37. WScript.Echo(L_Help2);
  38. WScript.Echo(L_Help3);
  39. WScript.Echo(L_Help4);
  40. WScript.Echo(L_Help5);
  41. WScript.Echo(L_Help6);
  42. }
  43. function CheckArguments()
  44. {
  45. Arguments = WScript.arguments;
  46. fDisable = false;
  47. if (Arguments.length < 1)
  48. {
  49. return fDisable;
  50. }
  51. if (Arguments.Item(0) == "/?")
  52. {
  53. PrintHelp();
  54. WScript.Quit(0);
  55. }
  56. if (Arguments.Item(0) == "/disable")
  57. {
  58. fDisable = true;
  59. }
  60. return fDisable;
  61. }
  62. fDisable = CheckArguments();
  63. iCount = 0;
  64. IIS_ANY_PROPERTY = 0;
  65. IIS_INHERITABLE_ONLY = 1
  66. vProperty = "BITSUploadEnabled";
  67. try
  68. {
  69. ServerObj = GetObject("IIS://LocalHost/W3SVC");
  70. PathListAsVBArray = ServerObj.GetDataPaths(vProperty,IIS_ANY_PROPERTY);
  71. PathList = PathListAsVBArray.toArray();
  72. }
  73. catch (Error)
  74. {
  75. WScript.Echo(L_FailedConnectToIIS + Error);
  76. WScript.Quit(1);
  77. }
  78. if (PathList.length == 0)
  79. {
  80. WScript.Echo(L_NoBitsDirectories);
  81. }
  82. //
  83. // We want to sort the list in reverse order so that we will disable sub-directories
  84. // (if any) first.
  85. //
  86. PathList.sort();
  87. PathList.reverse();
  88. if (fDisable)
  89. {
  90. WScript.Echo(L_DisableTitle);
  91. }
  92. else
  93. {
  94. WScript.Echo(L_ListTitle);
  95. }
  96. for (i in PathList)
  97. {
  98. Path = PathList[i];
  99. VDir = GetObject(Path);
  100. if (VDir.BITSUploadEnabled)
  101. {
  102. iCount = iCount + 1;
  103. if (fDisable)
  104. {
  105. WScript.Echo(L_Disabling + Path);
  106. try
  107. {
  108. VDir.DisableBitsUploads();
  109. }
  110. catch (Error)
  111. {
  112. WScript.Echo(L_FailedToDisable + Error);
  113. }
  114. }
  115. else
  116. {
  117. WScript.Echo(L_Enabled + Path);
  118. }
  119. }
  120. else
  121. {
  122. WScript.Echo(L_Disabled + Path);
  123. }
  124. }
  125. WScript.Echo(L_TotalCount + iCount );
  126. WScript.Quit(0);