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.

197 lines
5.7 KiB

  1. '********************************************************************
  2. '*
  3. '* File: ExtensionsTest.VBS
  4. '* Created: March 2000
  5. '*
  6. '* Main Function: Adds snapins, enumerates extensions, enables
  7. '* disables the extension snapins.
  8. '* Usage: ExtensionTest.VBS
  9. '*
  10. '* Copyright (C) 2000 Microsoft Corporation
  11. '*
  12. '********************************************************************
  13. OPTION EXPLICIT
  14. 'Define constants
  15. 'Declare variables
  16. Dim mmc
  17. Dim doc
  18. Dim snapins
  19. Dim Services
  20. Dim ServicesExtensions
  21. Dim ServicesExtension
  22. Dim Compmgmt
  23. Dim CompmgmtExtensions
  24. Dim CompmgmtExtension
  25. Dim message
  26. Dim intRet
  27. 'get the various objects we'll need
  28. Set mmc = wscript.CreateObject("MMC20.Application")
  29. Set doc = mmc.Document
  30. Set snapins = doc.snapins
  31. 'add services & compmgmt snapins
  32. Set Services = snapins.Add("{58221c66-ea27-11cf-adcf-00aa00a80033}") ' Services snapin
  33. Set Compmgmt = snapins.Add("{58221C67-EA27-11CF-ADCF-00AA00A80033}") ' Compmgmt snapin
  34. EnumerateExtensions(Services)
  35. EnumerateExtensions(Compmgmt)
  36. DisableAnExtension Services, "Send"
  37. Services.EnableAllExtensions(1)
  38. message = "Please verify all extensions of " & Services.Name & "are enabled."
  39. intRet = MsgBox(message, vbInformation, "Verify test")
  40. ' Now remove Services & try to disable the extension
  41. RemoveSnapinAndEnableExtension Services, "Send"
  42. Set mmc = Nothing
  43. '********************************************************************
  44. '*
  45. '* Sub Welcome
  46. '*
  47. '********************************************************************
  48. Sub Welcome()
  49. Dim intDoIt
  50. intDoIt = MsgBox(L_Welcome_MsgBox_Message_Text, _
  51. vbOKCancel + vbInformation, _
  52. L_Welcome_MsgBox_Title_Text )
  53. If intDoIt = vbCancel Then
  54. WScript.Quit
  55. End If
  56. End Sub
  57. '********************************************************************
  58. '*
  59. '* Sub EnumerateExtensions(objSnapin)
  60. '* Purpose: Enumberates the extensions of the given snapin.
  61. '* Input: objSnapin given snapin.
  62. '*
  63. '* Output: Results of the enumeration are either printed on screen or saved in strOutputFile.
  64. '*
  65. '********************************************************************
  66. Sub EnumerateExtensions(objSnapin)
  67. ON ERROR RESUME NEXT
  68. Dim Extensions
  69. Dim Extension
  70. Dim SnapinName
  71. Dim ExtensionNames
  72. Dim count
  73. Dim OtherData
  74. Set Extensions = objSnapin.Extensions
  75. count = Extensions.Count
  76. If count > 0 Then
  77. SnapinName = objSnapin.Name
  78. OtherData = "Vendor : " + objSnapin.Vendor
  79. OtherData = OtherData + ", Version : " + objSnapin.Version
  80. OtherData = OtherData + ", CLSID : " + objSnapin.SnapinCLSID
  81. intRet = MsgBox(OtherData, vbInformation, "About Information for " & SnapinName)
  82. For Each Extension in Extensions
  83. ExtensionNames = ExtensionNames + Extension.Name
  84. ExtensionNames = ExtensionNames + ","
  85. EnumerateExtensions(Extension)
  86. Next
  87. ExtensionNames = ExtensionNames + "."
  88. intRet = MsgBox(ExtensionNames, vbInformation, "Extensions for " & SnapinName)
  89. End If
  90. End Sub
  91. '********************************************************************
  92. '*
  93. '* Function FindExtension(objSnapin,strExtension)
  94. '* Purpose: Finds an extension for given primary snapin with given name.
  95. '* Input: objSnapin given snapin.
  96. '* strExtension given extension name.
  97. '*
  98. '* Output: returns true if extension exists. objExtension carries the returned object.
  99. '*
  100. '********************************************************************
  101. Function FindExtension(objSnapin, strExtension, objExtension)
  102. Dim Extensions
  103. Dim Extension
  104. Set Extensions = objSnapin.Extensions
  105. For Each objExtension in Extensions
  106. If InStr(objExtension.Name, strExtension) Then
  107. FindExtension = true
  108. Exit Function
  109. End If
  110. Next
  111. FindExtension = false
  112. End Function
  113. '********************************************************************
  114. '*
  115. '* Sub DisableAnExtension(objSnapin, strExtensionName)
  116. '* Purpose: Disables and extension of objSnapin with given name.
  117. '* Input: objSnapin given snapin.
  118. '*
  119. '* Output: Verify if the snapis is disabled.
  120. '*
  121. '********************************************************************
  122. Sub DisableAnExtension(objSnapin, strExtensionName)
  123. Dim Extension
  124. If FindExtension(objSnapin, strExtensionName, Extension) Then
  125. ObjSnapin.EnableAllExtensions(0)
  126. Extension.Enable(0)
  127. message = "Please verify disabling of " & Extension.Name & " extension of " & objSnapin.Name & "."
  128. intRet = MsgBox(message, vbInformation, "Verify test")
  129. Else
  130. message = "Extension for " & objSnapin.Name & " with name " & strExtensionName & " does not exist."
  131. intRet = MsgBox(message, vbInformation, "Verify test")
  132. End If
  133. End Sub
  134. '********************************************************************
  135. '*
  136. '* Sub RemoveSnapinAndEnableExtension(objSnapin, strExtensionName)
  137. '* Purpose: Finds the extension with given name, removes primary &
  138. '* accesses extension. This will fail as primary is gone.
  139. '* Input: objSnapin given snapin.
  140. '*
  141. '* Output: Verify error message is returned on enabling.
  142. '*
  143. '********************************************************************
  144. Sub RemoveSnapinAndEnableExtension(objSnapin, strExtensionName)
  145. ON ERROR RESUME NEXT
  146. Dim Extension
  147. If FindExtension(objSnapin, strExtensionName, Extension) Then
  148. snapins.Remove objSnapin
  149. Extension.Enable(1)
  150. MsgBox "Error # " & CStr(Err.Number) & " " & Err.Description
  151. Err.clear
  152. Else
  153. message = "Extension for " & objSnapin.Name & " with name " & strExtensionName & " does not exist."
  154. intRet = MsgBox(message, vbInformation, "Verify test")
  155. End If
  156. End Sub