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.

190 lines
4.1 KiB

  1. <!--
  2. ******************************************************************
  3. '
  4. ' copy.wsf
  5. '
  6. ' Purpose: test object copying
  7. '
  8. ' Parameters: none
  9. '
  10. ' Returns: 0 - success
  11. ' 1 - failure
  12. '
  13. '*****************************************************************
  14. -->
  15. <job id="WMI Copy 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\copy.txt"
  21. scriptHelper.loggingLevel = 3
  22. scriptHelper.testName = "WMI Copy"
  23. scriptHelper.testStart
  24. dim l
  25. dim ns
  26. TestPreamble
  27. TestCopy
  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 = "COPY000TEST"
  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 ("COPY000TEST").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. End Sub
  99. '******************************************************************
  100. '
  101. ' TestPostamble
  102. '
  103. ' Purpose: Create some objects for this test
  104. '
  105. '*****************************************************************
  106. Sub TestPostamble
  107. on error resume next
  108. ' Clean up
  109. ns.Delete ("COPY000TEST")
  110. if err <> 0 then
  111. scriptHelper.writeErrorToLog err, "Failed to delete classes"
  112. else
  113. scriptHelper.writeToLog "Successful delete of classes", 2
  114. end if
  115. End Sub
  116. '******************************************************************
  117. '
  118. ' TestCopy
  119. '
  120. ' Purpose: test SWbemServicesEx vector functionality
  121. '
  122. '*****************************************************************
  123. Sub TestCopy
  124. on error resume next
  125. scriptHelper.writeToLog ">>>", 2
  126. scriptHelper.writeToLog ">>> TestCopy", 2
  127. scriptHelper.writeToLog ">>>", 2
  128. ' Open the instance to be copied
  129. set oInstance = ns.Get ("COPY000TEST=1")
  130. if err <> 0 then
  131. scriptHelper.writeErrorToLog err, "Failed to open instance"
  132. else
  133. scriptHelper.writeToLog "Successful opening of instance", 2
  134. end if
  135. 'Now copy it
  136. set nInstance = oInstance.CopyTo_ ("COPY000TEST=2")
  137. if err <> 0 then
  138. scriptHelper.writeErrorToLog err, "Failed to copy instance"
  139. else
  140. scriptHelper.writeToLog "Successful copy of instance: " & nInstance.Path_.Path, 2
  141. end if
  142. scriptHelper.writeToLog "<<<", 2
  143. scriptHelper.writeToLog "<<< TestCopy", 2
  144. scriptHelper.writeToLog "<<<", 2
  145. End Sub
  146. </script>
  147. </job>