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.

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