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.

214 lines
5.0 KiB

  1. <!--
  2. ******************************************************************
  3. '
  4. ' move.wsf
  5. '
  6. ' Purpose: test object moving
  7. '
  8. ' Parameters: none
  9. '
  10. ' Returns: 0 - success
  11. ' 1 - failure
  12. '
  13. '*****************************************************************
  14. -->
  15. <job id="WMI Move 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\move.txt"
  21. scriptHelper.loggingLevel = 3
  22. scriptHelper.testName = "WMI Move"
  23. scriptHelper.testStart
  24. dim l
  25. dim ns, ns2
  26. TestPreamble
  27. TestMove
  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 class
  61. set newClass = ns.Get
  62. if err <> 0 then
  63. scriptHelper.writeErrorToLog err, "Failed to get empty class"
  64. else
  65. scriptHelper.writeToLog "Successful retrieval of empty class", 2
  66. end if
  67. newClass.Path_.Class = "MOVE000TEST"
  68. ' Add a key property (uint32)
  69. set p0 = newClass.Properties_.Add ("p0", wbemCimtypeUint32)
  70. p0.Qualifiers_.Add "key", true
  71. if err <> 0 then
  72. scriptHelper.writeErrorToLog err, "Failed to define class"
  73. else
  74. scriptHelper.writeToLog "Successful definition of class", 2
  75. end if
  76. ' Save the class
  77. newClass.Put_
  78. if err <> 0 then
  79. scriptHelper.writeErrorToLog err, "Failed to save class"
  80. else
  81. scriptHelper.writeToLog "Successful save of class", 2
  82. end if
  83. ' Get it back and make an instance
  84. set newInstance = ns.Get ("MOVE000TEST").SpawnInstance_
  85. if err <> 0 then
  86. scriptHelper.writeErrorToLog err, "Failed to get new instance"
  87. else
  88. scriptHelper.writeToLog "Successful get of new instance", 2
  89. end if
  90. ' Create an instance
  91. newInstance.p0 = 1
  92. newInstance.Put_
  93. if err <> 0 then
  94. scriptHelper.writeErrorToLog err, "Failed to create instance"
  95. else
  96. scriptHelper.writeToLog "Successful creation of instance", 2
  97. end if
  98. ' Save the class in another namespace prior to the move
  99. set ns2 = GetObject("winmgmts:root\cimv2")
  100. set newClass = ns.Get("MOVE000TEST")
  101. ns2.Put (newClass)
  102. if err <> 0 then
  103. scriptHelper.writeErrorToLog err, "Failed to save class in 2nd namespace"
  104. else
  105. scriptHelper.writeToLog "Successful save of class in 2nd namespace", 2
  106. end if
  107. End Sub
  108. '******************************************************************
  109. '
  110. ' TestPostamble
  111. '
  112. ' Purpose: Create some objects for this test
  113. '
  114. '*****************************************************************
  115. Sub TestPostamble
  116. on error resume next
  117. ' Clean up
  118. ns.Delete ("MOVE000TEST")
  119. ns2.Delete ("MOVE000TEST")
  120. if err <> 0 then
  121. scriptHelper.writeErrorToLog err, "Failed to delete classes"
  122. else
  123. scriptHelper.writeToLog "Successful delete of classes", 2
  124. end if
  125. End Sub
  126. '******************************************************************
  127. '
  128. ' TestMove
  129. '
  130. ' Purpose: test move functionality
  131. '
  132. '*****************************************************************
  133. Sub TestMove
  134. on error resume next
  135. scriptHelper.writeToLog ">>>", 2
  136. scriptHelper.writeToLog ">>> TestMove", 2
  137. scriptHelper.writeToLog ">>>", 2
  138. ' Open the instance to be moved
  139. set oInstance = ns.Get ("MOVE000TEST=1")
  140. if err <> 0 then
  141. scriptHelper.writeErrorToLog err, "Failed to open instance"
  142. else
  143. scriptHelper.writeToLog "Successful opening of instance", 2
  144. end if
  145. 'Now move it
  146. set nInstance = oInstance.MoveTo_ ("root\cimv2:MOVE000TEST=2")
  147. if err <> 0 then
  148. scriptHelper.writeErrorToLog err, "Failed to move instance"
  149. else
  150. scriptHelper.writeToLog "Successful move of instance: " & nInstance.Path_.Path, 2
  151. end if
  152. ' Should have moved "in-place"
  153. if nInstance.Path_.Namespace <> "root\cimv2" then
  154. scriptHelper.writeErrorToLog err, "Wrong namespace [root\cimv2]: " & nInstance.Path_.Namespace
  155. else
  156. scriptHelper.writeToLog "Namespace path is correct: " & nInstance.Path_.Namespace, 2
  157. end if
  158. if nInstance.p0 <> 2 then
  159. scriptHelper.writeErrorToLog err, "Wrong key [2]: " & nInstance.p0
  160. else
  161. scriptHelper.writeToLog "Key is correct: " & nInstance.p0, 2
  162. end if
  163. scriptHelper.writeToLog "<<<", 2
  164. scriptHelper.writeToLog "<<< TestMove", 2
  165. scriptHelper.writeToLog "<<<", 2
  166. End Sub
  167. </script>
  168. </job>