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.

227 lines
5.5 KiB

  1. <!--
  2. ******************************************************************
  3. '
  4. ' vector.wsf
  5. '
  6. ' Purpose: test vectors
  7. '
  8. ' Parameters: none
  9. '
  10. ' Returns: 0 - success
  11. ' 1 - failure
  12. '
  13. '*****************************************************************
  14. -->
  15. <job id="WMI Vector Test">
  16. <reference object="WbemScripting.SWbemLocator" version="1.2"/>
  17. <script language="VBScript">
  18. on error resume next
  19. set scriptHelper = CreateObject("WMIScriptHelper.WSC")
  20. scriptHelper.logFile = "c:\temp\vector.txt"
  21. scriptHelper.loggingLevel = 3
  22. scriptHelper.testName = "WMI Vector"
  23. scriptHelper.testStart
  24. dim l
  25. dim ns
  26. TestPreamble
  27. TestVectorOpen
  28. TestPostamble
  29. scriptHelper.testComplete
  30. if scriptHelper.statusOK then
  31. WScript.Echo "PASS"
  32. WScript.Quit 0
  33. else
  34. WScript.Echo "FAIL"
  35. WScript.Quit 1
  36. end if
  37. '******************************************************************
  38. '
  39. ' TestPreamble
  40. '
  41. ' Purpose: Create some objects for this test
  42. '
  43. '*****************************************************************
  44. Sub TestPreamble
  45. on error resume next
  46. ' Create a locator
  47. set l = CreateObject("WbemScripting.SWbemLocatorEx")
  48. if err <> 0 then
  49. scriptHelper.writeErrorToLog err, "Failed to create locator"
  50. else
  51. scriptHelper.writeToLog "Successful creation of locator", 2
  52. end if
  53. ' Connect to the namespace
  54. set ns = l.ConnectServer (,"root\default")
  55. if err <> 0 then
  56. scriptHelper.writeErrorToLog err, "Failed to connect to root\default"
  57. else
  58. scriptHelper.writeToLog "Successful connection to root\default", 2
  59. end if
  60. ' Make a new sub-namespace
  61. set newNamespace = ns.Get("__Namespace").SpawnInstance_
  62. if err <> 0 then
  63. scriptHelper.writeErrorToLog err, "Failed to get new namespace"
  64. else
  65. scriptHelper.writeToLog "Successful get of new namespace", 2
  66. end if
  67. newNamespace.Name = "endpoint"
  68. newNamespace.Put_
  69. if err <> 0 then
  70. scriptHelper.writeErrorToLog err, "Failed to create new namespace"
  71. else
  72. scriptHelper.writeToLog "Successful creation of new namespace", 2
  73. end if
  74. 'Make a new class
  75. set newClass = ns.Get
  76. if err <> 0 then
  77. scriptHelper.writeErrorToLog err, "Failed to get empty class"
  78. else
  79. scriptHelper.writeToLog "Successful retrieval of empty class", 2
  80. end if
  81. newClass.Path_.Class = "VECTOR000TEST"
  82. newClass.Qualifiers_.Add "vector", true
  83. ' Add a key property (uint32)
  84. set p0 = newClass.Properties_.Add ("p0", wbemCimtypeUint32)
  85. p0.Qualifiers_.Add "key", true
  86. ' Add the vector pointer
  87. set pV = newClass.Properties_.Add ("pV", wbemCimtypeReference)
  88. if err <> 0 then
  89. scriptHelper.writeErrorToLog err, "Failed to define class"
  90. else
  91. scriptHelper.writeToLog "Successful definition of class", 2
  92. end if
  93. ' Save the class
  94. newClass.Put_
  95. if err <> 0 then
  96. scriptHelper.writeErrorToLog err, "Failed to save class"
  97. else
  98. scriptHelper.writeToLog "Successful save of class", 2
  99. end if
  100. ' Get it back and make an instance
  101. set newInstance = ns.Get ("VECTOR000TEST").SpawnInstance_
  102. if err <> 0 then
  103. scriptHelper.writeErrorToLog err, "Failed to get new instance"
  104. else
  105. scriptHelper.writeToLog "Successful get of new instance", 2
  106. end if
  107. ' Create an instance
  108. newInstance.p0 = 1
  109. newInstance.pV = "\\.\root\default:__Namespace='endpoint'"
  110. newInstance.Put_
  111. if err <> 0 then
  112. scriptHelper.writeErrorToLog err, "Failed to create endpoint instance"
  113. else
  114. scriptHelper.writeToLog "Successful creation of instance", 2
  115. end if
  116. ' Bind to the new namespace
  117. set ns2 = GetObject("winmgmts:root\default\endpoint")
  118. set newClass = ns2.Get
  119. newClass.Path_.Class = "VECTOR001TEST"
  120. newClass.Put_
  121. if err <> 0 then
  122. scriptHelper.writeErrorToLog err, "Failed to create class in endpoint namespace"
  123. else
  124. scriptHelper.writeToLog "Successful creation of class in endpoint namespace", 2
  125. end if
  126. End Sub
  127. '******************************************************************
  128. '
  129. ' TestPostamble
  130. '
  131. ' Purpose: Create some objects for this test
  132. '
  133. '*****************************************************************
  134. Sub TestPostamble
  135. on error resume next
  136. ' Clean up
  137. ns.Delete ("__Namespace='endpoint'")
  138. ns.Delete ("VECTOR001TEST")
  139. if err <> 0 then
  140. scriptHelper.writeErrorToLog err, "Failed to delete classes"
  141. else
  142. scriptHelper.writeToLog "Successful delete of classes", 2
  143. end if
  144. End Sub
  145. '******************************************************************
  146. '
  147. ' TestVectorOpen
  148. '
  149. ' Purpose: test SWbemServicesEx vector functionality
  150. '
  151. '*****************************************************************
  152. Sub TestVectorOpen
  153. on error resume next
  154. scriptHelper.writeToLog ">>>", 2
  155. scriptHelper.writeToLog ">>> TestVectorOpen", 2
  156. scriptHelper.writeToLog ">>>", 2
  157. ' Open the instance as a vector
  158. set vector = ns.Open ("CONTAINER000TEST=1", wbemConnectionFlagOpenVector _
  159. OR wbemConnectionFlagAllowNamespaceTraversal OR wbemConnectionFlagAllowMachineTraversal)
  160. if err <> 0 then
  161. scriptHelper.writeErrorToLog err, "Failed to open instance as vector"
  162. else
  163. scriptHelper.writeToLog "Successful opening of instance as vector", 2
  164. end if
  165. 'Just to check we're in the right place, get our class
  166. set newClass = vector.Get ("VECTOR001TEST")
  167. if err <> 0 then
  168. scriptHelper.writeErrorToLog err, "Failed to get class from dereferenced vector"
  169. else
  170. scriptHelper.writeToLog "Successful retrieval of class from dereferenced vector: " & newClass.Path_.Path, 2
  171. end if
  172. scriptHelper.writeToLog "<<<", 2
  173. scriptHelper.writeToLog "<<< TestVectorOpen", 2
  174. scriptHelper.writeToLog "<<<", 2
  175. End Sub
  176. </script>
  177. </job>