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.

158 lines
4.3 KiB

  1. '*********************************************************************
  2. '
  3. ' put.vbs
  4. '
  5. ' Purpose: test SWbemServicesEx::Put functionality
  6. '
  7. ' Parameters: none
  8. '
  9. ' Returns: 0 - success
  10. ' 1 - failure
  11. '
  12. '*********************************************************************
  13. on error resume next
  14. set scriptHelper = CreateObject("WMIScriptHelper.WSC")
  15. scriptHelper.logFile = "c:\temp\put.txt"
  16. scriptHelper.loggingLevel = 3
  17. scriptHelper.testName = "PUT"
  18. scriptHelper.appendLog = false
  19. scriptHelper.testStart
  20. '*****************************
  21. ' Create a new class
  22. '*****************************
  23. set ns = GetObject ("winmgmts:root\default")
  24. if err <> 0 then
  25. scriptHelper.writeErrorToLog err, "Failed to connect to namespace"
  26. else
  27. scriptHelper.writeToLog "Connected to namespace correctly", 2
  28. end if
  29. set newClass = ns.Get ()
  30. if err <> 0 then
  31. scriptHelper.writeErrorToLog err, "Failed to create new class"
  32. else
  33. scriptHelper.writeToLog "New class created correctly", 2
  34. end if
  35. newClass.Path_.Class = "freddy"
  36. if err <> 0 then
  37. scriptHelper.writeErrorToLog err, "Failed to set class name"
  38. else
  39. scriptHelper.writeToLog "New class name set correctly", 2
  40. end if
  41. '*****************************
  42. ' Define a key
  43. '*****************************
  44. set property = newClass.Properties_.Add ("foo", 19)
  45. if err <> 0 then
  46. scriptHelper.writeErrorToLog err, "Failed to add property"
  47. else
  48. scriptHelper.writeToLog "New property added correctly", 2
  49. end if
  50. '*****************************
  51. ' Define a key
  52. '*****************************
  53. property.Qualifiers_.Add "key", true
  54. if err <> 0 then
  55. scriptHelper.writeErrorToLog err, "Failed to add key qualifier"
  56. else
  57. scriptHelper.writeToLog "Key qualifier added correctly", 2
  58. end if
  59. '*****************************
  60. ' Save it in the current namespace
  61. '*****************************
  62. ns.Put (newClass)
  63. if err <> 0 then
  64. scriptHelper.writeErrorToLog err, "Failed to save class"
  65. else
  66. scriptHelper.writeToLog "Class saved correctly", 2
  67. end if
  68. '*****************************
  69. ' Save it in another namespace
  70. '*****************************
  71. set ns2 = GetObject ("winmgmts:root\cimv2")
  72. if err <> 0 then
  73. scriptHelper.writeErrorToLog err, "Failed to open 2nd namespace"
  74. else
  75. scriptHelper.writeToLog "Opened 2nd namespace correctly", 2
  76. end if
  77. ns2.Put (newClass)
  78. if err <> 0 then
  79. scriptHelper.writeErrorToLog err, "Failed to save class in 2nd namespace"
  80. else
  81. scriptHelper.writeToLog "Saved class in 2nd namespace correctly", 2
  82. end if
  83. '*****************************
  84. ' Create a new instance
  85. '*****************************
  86. set newClass = ns.Get ("freddy")
  87. if err <> 0 then
  88. scriptHelper.writeErrorToLog err, "Failed to retrieve class"
  89. else
  90. scriptHelper.writeToLog "Retrieved class correctly", 2
  91. end if
  92. set newInstance = newClass.SpawnInstance_
  93. if err <> 0 then
  94. scriptHelper.writeErrorToLog err, "Failed to spawn instance"
  95. else
  96. scriptHelper.writeToLog "Spawned instance correctly", 2
  97. end if
  98. newInstance.foo = 10
  99. if err <> 0 then
  100. scriptHelper.writeErrorToLog err, "Failed to set key"
  101. else
  102. scriptHelper.writeToLog "Set key correctly", 2
  103. end if
  104. '*****************************
  105. ' Save in both namespaces
  106. '*****************************
  107. set path1 = ns.Put (newInstance)
  108. if err <> 0 then
  109. scriptHelper.writeErrorToLog err, "Failed to save instance to 1st namespace"
  110. else
  111. scriptHelper.writeToLog "Saved instance to 1st namespace correctly", 2
  112. end if
  113. set path2 = ns2.Put (newInstance)
  114. if err <> 0 then
  115. scriptHelper.writeErrorToLog err, "Failed to save instance to 2nd namespace"
  116. else
  117. scriptHelper.writeToLog "Saved instance to 2nd namespace correctly", 2
  118. end if
  119. '*****************************
  120. ' Check for correct namespace
  121. '*****************************
  122. if path1.Namespace <> "root\default" then
  123. scriptHelper.writeErrorToLog null, "First namespace is incorrect: " & path1.Namespace
  124. else
  125. scriptHelper.writeToLog "First namespace is correct", 2
  126. end if
  127. if path2.Namespace <> "root\cimv2" then
  128. scriptHelper.writeErrorToLog null, "Second namespace is incorrect: " & path2.Namespace
  129. else
  130. scriptHelper.writeToLog "Second namespace is correct", 2
  131. end if
  132. scriptHelper.testComplete
  133. if scriptHelper.statusOK then
  134. WScript.Echo "PASS"
  135. WScript.Quit 0
  136. else
  137. WScript.Echo "FAIL"
  138. WScript.Quit 1
  139. end if