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
3.9 KiB

  1. '*********************************************************************
  2. '
  3. ' sysprop.vbs
  4. '
  5. ' Purpose: test system property 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\sysprop.txt"
  16. scriptHelper.loggingLevel = 3
  17. scriptHelper.testName = "SYSPROP"
  18. scriptHelper.testStart
  19. '*****************************
  20. ' Get a disk
  21. '*****************************
  22. set disk = GetObject ("winmgmts:root\cimv2:Win32_LogicalDisk='C:'")
  23. if err <> 0 then
  24. scriptHelper.writeErrorToLog err, "Failed to get test instance"
  25. else
  26. scriptHelper.writeToLog "Test instance retrieved correctly", 2
  27. end if
  28. '*****************************
  29. ' Get the __CLASS property
  30. '*****************************
  31. className = disk.SystemProperties_("__CLASS")
  32. if err <> 0 then
  33. scriptHelper.writeErrorToLog err, "Failed to get __CLASS"
  34. elseif "Win32_LogicalDisk" <> className then
  35. scriptHelper.writeErrorToLog null, "__CLASS value is incorrect"
  36. else
  37. scriptHelper.writeToLog "__CLASS retrieved correctly", 2
  38. end if
  39. '*****************************
  40. ' Try to add a property - should fail
  41. '*****************************
  42. disk.SystemProperties_.Add "__FRED", 8
  43. if err <> 0 then
  44. scriptHelper.writeToLog "Expected failure to add a system property", 2
  45. err.clear
  46. else
  47. scriptHelper.writeErrorToLog null, "Unexpectedly successful addition of system property"
  48. end if
  49. '*****************************
  50. ' Iterate through the system properties
  51. '*****************************
  52. EnumerateProperties disk
  53. '*****************************
  54. ' Count the system properties
  55. '*****************************
  56. spCount = disk.SystemProperties_.Count
  57. if err <> 0 then
  58. scriptHelper.writeErrorToLog err, "Error retrieving Count"
  59. else
  60. scriptHelper.writeToLog "There are " & spCount & " system properties", 2
  61. end if
  62. '*****************************
  63. ' Get an empty class
  64. '*****************************
  65. set emptyClass = GetObject("winmgmts:root\default").Get
  66. if err <> 0 then
  67. scriptHelper.writeErrorToLog err, "Failed to get empty test class"
  68. else
  69. scriptHelper.writeToLog "Empty test class retrieved correctly", 2
  70. end if
  71. '*****************************
  72. ' Set the __CLASS property
  73. '*****************************
  74. emptyClass.SystemProperties_("__CLASS").Value = "Stavisky"
  75. if err <> 0 then
  76. scriptHelper.writeErrorToLog err, "Failed to set __CLASS in empty class"
  77. else
  78. scriptHelper.writeToLog "__CLASS set in empty class correctly", 2
  79. end if
  80. if emptyClass.Path_.Class <> "Stavisky" then
  81. scriptHelper.writeErrorToLog null, "Incorrect class name set in path"
  82. else
  83. scriptHelper.writeToLog "Class name set in path correctly", 2
  84. end if
  85. scriptHelper.testComplete
  86. if scriptHelper.statusOK then
  87. WScript.Echo "PASS"
  88. WScript.Quit 0
  89. else
  90. WScript.Echo "FAIL"
  91. WScript.Quit 1
  92. end if
  93. Sub EnumerateProperties (obj)
  94. scriptHelper.writeToLog "Enumerating all properties...", 2
  95. for each property in obj.SystemProperties_
  96. scriptHelper.writeToLog " " & property.Name & " - " & property.CIMType, 2
  97. value = property.Value
  98. if IsNull(value) then
  99. scriptHelper.writeToLog " Value: <null>", 2
  100. elseif property.IsArray then
  101. valueStr = "["
  102. for i = LBound(value) to UBound(value)
  103. valueStr = valueStr + value(i)
  104. if i < UBound(value) then valueStr = valueStr + ", "
  105. next
  106. valueStr = valueStr + "]"
  107. scriptHelper.writeToLog " Value: " & valueStr, 2
  108. else
  109. scriptHelper.writeToLog " Value: " & property.Value, 2
  110. end if
  111. if err <> 0 then scriptHelper.writeErrorToLog err, "Hmm"
  112. next
  113. if err <> 0 then
  114. scriptHelper.writeErrorToLog err, "...Failed to enumerate"
  115. else
  116. scriptHelper.writeToLog "...Enumeration complete", 2
  117. end if
  118. End Sub