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.

215 lines
4.9 KiB

  1. <!--
  2. ******************************************************************
  3. '
  4. ' rename.wsf
  5. '
  6. ' Purpose: test object renaming
  7. '
  8. ' Parameters: none
  9. '
  10. ' Returns: 0 - success
  11. ' 1 - failure
  12. '
  13. '*****************************************************************
  14. -->
  15. <job id="WMI Rename 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\rename.txt"
  21. scriptHelper.loggingLevel = 3
  22. scriptHelper.testName = "WMI Rename"
  23. scriptHelper.testStart
  24. dim l
  25. dim ns
  26. TestPreamble
  27. TestRename
  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 = "RENAME000TEST"
  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 ("RENAME000TEST").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 ("RENAME000TEST")
  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. ' TestRename
  119. '
  120. ' Purpose: test rename functionality
  121. '
  122. '*****************************************************************
  123. Sub TestRename
  124. on error resume next
  125. scriptHelper.writeToLog ">>>", 2
  126. scriptHelper.writeToLog ">>> TestRename", 2
  127. scriptHelper.writeToLog ">>>", 2
  128. ' Open the instance to be renamed
  129. set oInstance = ns.Get ("RENAME000TEST=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 rename it
  136. oInstance.RenameTo_ ("RENAME000TEST=2")
  137. if err <> 0 then
  138. scriptHelper.writeErrorToLog err, "Failed to rename instance"
  139. else
  140. scriptHelper.writeToLog "Successful rename of instance", 2
  141. end if
  142. ' Should have been renamed in place
  143. if oInstance.p0 = 2 then
  144. scriptHelper.writeToLog "Instance has correct in-place key", 2
  145. else
  146. scriptHelper.writeErrorToLog err, "Wrong in-place key [2]; " & oInstance.p0
  147. end if
  148. 'Check we can get the new one
  149. set inst = ns.Get ("RENAME000TEST=2")
  150. if err <> 0 then
  151. scriptHelper.writeErrorToLog err, "Failed to get renamed instance"
  152. else
  153. scriptHelper.writeToLog "Successful get of renamed instance", 2
  154. end if
  155. 'Check we can't get the old one
  156. set inst = ns.Get ("RENAME000TEST=1")
  157. if wbemErrNotFound = err.Number then
  158. scriptHelper.writeToLog "Successful removal of original instance", 2
  159. err.Clear
  160. else
  161. scriptHelper.writeErrorToLog err, "Failed to remove original instance"
  162. end if
  163. scriptHelper.writeToLog "<<<", 2
  164. scriptHelper.writeToLog "<<< TestRename", 2
  165. scriptHelper.writeToLog "<<<", 2
  166. End Sub
  167. </script>
  168. </job>