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.

136 lines
4.4 KiB

  1. VERSION 5.00
  2. Begin VB.Form Form1
  3. Caption = "Form1"
  4. ClientHeight = 3195
  5. ClientLeft = 60
  6. ClientTop = 345
  7. ClientWidth = 4680
  8. LinkTopic = "Form1"
  9. ScaleHeight = 3195
  10. ScaleWidth = 4680
  11. StartUpPosition = 3 'Windows Default
  12. End
  13. Attribute VB_Name = "Form1"
  14. Attribute VB_GlobalNameSpace = False
  15. Attribute VB_Creatable = False
  16. Attribute VB_PredeclaredId = True
  17. Attribute VB_Exposed = False
  18. Private Sub Form_Load()
  19. '***************************************************************************
  20. 'This script tests the manipulation of property values, in the case that the
  21. 'property is an array type
  22. '***************************************************************************
  23. Dim Service As SWbemServices
  24. Dim Class As SWbemObject
  25. Dim P As SWbemProperty
  26. Set Service = GetObject("winmgmts:root/default")
  27. On Error Resume Next
  28. Set Class = Service.Get()
  29. Class.Path_.Class = "ARRAYPROP00"
  30. Set P = Class.Properties_.Add("p1", wbemCimtypeUint32, True)
  31. P.Value = Array(1, 2, 3)
  32. myStr = "The initial value of p1 is {"
  33. For x = LBound(P.Value) To UBound(P.Value)
  34. myStr = myStr & Class.Properties_("p1")(x)
  35. If x <> UBound(Class.Properties_("p1").Value) Then
  36. myStr = myStr & ", "
  37. End If
  38. Next
  39. myStr = myStr & "}"
  40. Debug.Print myStr
  41. '****************************************
  42. 'First pass of tests works on non-dot API
  43. '****************************************
  44. 'Verify we can report the value of an element of the property value
  45. v = Class.Properties_("p1")
  46. Debug.Print "By indirection the first element of p1 had value:" & v(0)
  47. 'Verify we can report the value directly
  48. Debug.Print "By direct access the first element of p1 has value:" & Class.Properties_("p1")(0)
  49. 'Verify we can set the value of a single property value element
  50. ' this won't work because VB will use the vtable interface
  51. Class.Properties_("p1")(1) = 234
  52. Debug.Print "After direct assignment the first element of p1 has value:" & Class.Properties_("p1")(1)
  53. 'Verify we can set the value of a single property value element
  54. 'this does work because v is typeless and VB therefore uses the dispatch interface
  55. Set v = Class.Properties_("p1")
  56. v(1) = 345
  57. Debug.Print "After indirect assignment the first element of p1 has value:" & Class.Properties_("p1")(1)
  58. 'Verify we can set the value of an entire property value
  59. Class.Properties_("p1") = Array(5, 34, 178871)
  60. Debug.Print "After direct array assignment the first element of p1 has value:" & Class.Properties_("p1")(1)
  61. myStr = "After direct assignment the entire value of p1 is {"
  62. For x = LBound(P.Value) To UBound(P.Value)
  63. myStr = myStr & Class.Properties_("p1")(x)
  64. If x <> UBound(P.Value) Then
  65. myStr = myStr & ", "
  66. End If
  67. Next
  68. myStr = myStr & "}"
  69. Debug.Print myStr
  70. If Err <> 0 Then
  71. WScript.Echo Err.Description
  72. Err.Clear
  73. End If
  74. '****************************************
  75. 'Second pass of tests works on dot API
  76. '****************************************
  77. 'Verify we can report the array of a property using the dot notation
  78. myStr = "By direct access via the dot notation the entire value of p1 is {"
  79. For x = LBound(Class.p1) To UBound(Class.p1)
  80. myStr = myStr & Class.p1(x)
  81. If x <> UBound(Class.p1) Then
  82. myStr = myStr & ", "
  83. End If
  84. Next
  85. myStr = myStr & "}"
  86. Debug.Print myStr
  87. 'Verify we can report the value of a property array element using the "dot" notation
  88. Debug.Print "By direct access the first element of p1 has value:" & Class.p1(0)
  89. 'Verify we can report the value of a property array element using the "dot" notation
  90. v = Class.p1
  91. Debug.Print "By direct access the first element of p1 has value:" & v(0)
  92. 'Verify we can set the value of a property array element using the "dot" notation
  93. Class.p1(2) = 8889
  94. Debug.Print "By direct access the second element of p1 has been set to:" & Class.p1(2)
  95. 'Verify we can set the entire array value using dot notation
  96. Class.p1 = Array(412, 3, 544)
  97. myStr = "By direct access via the dot notation the entire value of p1 has been set to {"
  98. For x = LBound(Class.p1) To UBound(Class.p1)
  99. myStr = myStr & Class.p1(x)
  100. If x <> UBound(Class.p1) Then
  101. myStr = myStr & ", "
  102. End If
  103. Next
  104. myStr = myStr & "}"
  105. Debug.Print myStr
  106. 'Service.Put (Class)
  107. If Err <> 0 Then
  108. WScript.Echo Err.Description
  109. Err.Clear
  110. End If
  111. 'Set C = S.Get("a")
  112. 'v = C.p(0)
  113. 'C.p = vbEmpty
  114. 'VV = C.p(0)
  115. 'S.Put C
  116. End Sub