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.

146 lines
4.8 KiB

  1. '***************************************************************************
  2. 'This script tests the manipulation of property values, in the case that the
  3. 'property is an embedded type
  4. '***************************************************************************
  5. On Error Resume Next
  6. while true
  7. Set Service = GetObject("winmgmts:root/default")
  8. '*******************************
  9. 'Create an embedded object class
  10. '*******************************
  11. '
  12. ' [woobit(24.5)]
  13. ' class EmObjInner {
  14. ' [key] uint32 pInner = 10;
  15. ' };
  16. '
  17. Set EmbObjInner = Service.Get()
  18. EmbObjInner.Path_.Class = "EmbObjInner"
  19. EmbObjInner.Qualifiers_.Add "woobit", 24.5
  20. Set Property = EmbObjInner.Properties_.Add ("pInner", 19)
  21. Property.Qualifiers_.Add "key", true
  22. Property.Value = 10
  23. EmbObjInner.Put_
  24. Set EmbObjInner = Service.Get("EmbObjInner")
  25. if Err <> 0 Then
  26. WScript.Echo Err.Description
  27. Err.Clear
  28. End if
  29. '************************************
  30. 'Create another embedded object class
  31. '************************************
  32. '
  33. ' [wazzuck("oxter")]
  34. ' class EmbObjOuter {
  35. ' uint32 p0 = 25;
  36. ' EmbObjInner pOuter = instance of EmbObjInner { pInner = 564; };
  37. ' EmbObjInner pOuterArray[] = {
  38. ' instance of EmbObjInner { pInner = 0; },
  39. ' instance of EmbObjInner { pInner = 1; },
  40. ' instance of EmbObjInner { pInner = 2; }
  41. ' };
  42. ' };
  43. Set EmbObjOuter = Service.Get()
  44. EmbObjOuter.Path_.Class = "EmbObjOuter"
  45. EmbObjOuter.Qualifiers_.Add "wazzuck", "oxter"
  46. EmbObjOuter.Properties_.Add ("p0", 19).Value = 25
  47. Set Property = EmbObjOuter.Properties_.Add ("pOuter", 13)
  48. Set Instance = EmbObjInner.SpawnInstance_
  49. Instance.pInner = 564
  50. Property.Value = Instance
  51. ' Add an array of embedded objects property
  52. Set Property = EmbObjOuter.Properties_.Add ("pOuterArray", 13, true)
  53. Property.Qualifiers_.Add "cimtype","object:EmbObjInner"
  54. Set Instance0 = EmbObjInner.SpawnInstance_
  55. Instance0.pInner = 0
  56. Set Instance1 = EmbObjInner.SpawnInstance_
  57. Instance1.pInner = 1
  58. Set Instance2 = EmbObjInner.SpawnInstance_
  59. Instance2.pInner = 2
  60. Property.Value = Array (Instance0, Instance1, Instance2)
  61. Set Instance3 = EmbObjInner.SpawnInstance_
  62. Instance3.pInner = 42
  63. Property.Value(3) = Instance3
  64. Set Instance4 = EmbObjInner.SpawnInstance_
  65. Instance4.pInner = 78
  66. EmbObjOuter.pOuterArray (4) = Instance4
  67. EmbObjOuter.Put_
  68. Set EmbObjOuter = Service.Get("EmbObjOuter")
  69. if Err <> 0 Then
  70. WScript.Echo Err.Description
  71. Err.Clear
  72. End if
  73. 'Create a final class which wraps both embedded objects
  74. '
  75. '
  76. Set Class = Service.Get()
  77. Class.Path_.Class = "EMBPROPTEST01"
  78. Set Property = Class.Properties_.Add ("p1", 13)
  79. Set Instance = EmbObjOuter.SpawnInstance_
  80. Instance.p0 = 2546
  81. Property.Value = Instance
  82. Class.Put_
  83. WScript.Echo "The initial value of p0 is [2546]", Property.Value.p0
  84. WScript.Echo "The initial value of p0 is [2546]", Class.Properties_("p1").Value.Properties_("p0")
  85. WScript.Echo "The initial value of pInner is [564]", Property.Value.pOuter.pInner
  86. WScript.Echo "The initial value of pInner is [564]", _
  87. Class.Properties_("p1").Value.Properties_("pOuter").Value.Properties_("pInner")
  88. WScript.Echo "The initial value of EMBPROPTEST01.p1.pOuterArray(0).pInner is [0]:", Class.p1.pOuterArray(0).pInner
  89. WScript.Echo "The initial value of EMBPROPTEST01.p1.pOuterArray(1).pInner is [1]:", Class.p1.pOuterArray(1).pInner
  90. WScript.Echo "The initial value of EMBPROPTEST01.p1.pOuterArray(2).pInner is [2]:", Class.p1.pOuterArray(2).pInner
  91. WScript.Echo "The initial value of EMBPROPTEST01.p1.pOuterArray(3).pInner is [42]:", Class.p1.pOuterArray(3).pInner
  92. Set Class = Service.Get("EMBPROPTEST01")
  93. 'Now try direct assignment to the outer emb obj
  94. Class.p1.p0 = 23
  95. WScript.Echo "The new value of p0 is [23]", Class.p1.p0
  96. Set Property = Class.p1
  97. Property.p0 = 787
  98. WScript.Echo "The new value of p0 is [787]", Class.p1.p0
  99. Class.Properties_("p1").Value.p0 = 56
  100. WScript.Echo "The new value of p0 is [56]", Class.p1.p0
  101. 'Now try direct assignment to the inner emb obj
  102. Class.p1.pOuter.pInner = 4
  103. WScript.Echo "The new value of pInner is [4]", Class.p1.pOuter.pInner
  104. Set Property = Class.p1.pOuter
  105. Property.pInner = 12
  106. WScript.Echo "The new value of pInner is [12]", Class.p1.pOuter.pInner
  107. 'Now try assignment to the inner emb obj array
  108. Class.p1.pOuterArray(1).pInner = 5675
  109. WScript.Echo "The new value of Class.p1.pOuterArray(1).pInner is [5675]", Class.p1.pOuterArray(1).pInner
  110. 'None of the following will work because VBSCript needs to be told explicitly when to use
  111. 'a default automation property (i.e. they all require resolution to the "Value" property
  112. 'WScript.Echo "The initial value of p1 is", Class.Properties_("p1").p
  113. 'WScript.Echo "The initial value of p1 is", Class.Properties_("p1").Properties_("p")
  114. 'WScript.Echo "The initial value of p1 is", Property.p
  115. if Err <> 0 Then
  116. WScript.Echo Err.Description
  117. Err.Clear
  118. End if
  119. wend