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.

303 lines
5.7 KiB

  1. <?xml version="1.0"?>
  2. <component>
  3. <?component error="true" debug="true"?>
  4. <comment>This is a reusable scripted logging and status control</comment>
  5. <registration
  6. description="WMIScriptHelper"
  7. progid="WMIScriptHelper.WSC"
  8. version="1.00"
  9. classid="{db547feb-ec59-4004-968c-3920c88f3154}"
  10. >
  11. </registration>
  12. <public>
  13. <property name="logFile">
  14. <get/>
  15. <put/>
  16. </property>
  17. <property name="enableLogging">
  18. <get/>
  19. <put/>
  20. </property>
  21. <property name="loggingLevel">
  22. <get/>
  23. <put/>
  24. </property>
  25. <property name="statusOK">
  26. <get/>
  27. <put/>
  28. </property>
  29. <property name="testName">
  30. <get/>
  31. <put/>
  32. </property>
  33. <property name="appendLog">
  34. <get/>
  35. <put/>
  36. </property>
  37. <method name="writeToLog">
  38. <PARAMETER name="strText"/>
  39. <PARAMETER name="iLevel"/>
  40. </method>
  41. <method name="writeErrorToLog">
  42. <PARAMETER name="err"/>
  43. <PARAMETER name="strText"/>
  44. </method>
  45. <method name="testStart"/>
  46. <method name="testComplete"/>
  47. <method name="DisplayValue"/>
  48. <method name="VerifyValue"/>
  49. </public>
  50. <implements type="Behavior" id="Behavior"/>
  51. <script language="VBScript">
  52. <![CDATA[
  53. dim logFile
  54. logFile = "c:\temp\wmiscrp.txt"
  55. dim enableLogging
  56. enableLogging = true
  57. dim loggingLevel
  58. loggingLevel = 1
  59. dim statusOK
  60. statusOK = true
  61. dim testName
  62. testName = "Test"
  63. dim appendLog
  64. appendLog = false
  65. dim file
  66. function get_logFile()
  67. get_logFile = logFile
  68. end function
  69. function put_logFile(newValue)
  70. logFile = newValue
  71. end function
  72. function get_enableLogging()
  73. get_enableLogging = enableLogging
  74. end function
  75. function put_enableLogging(newValue)
  76. enableLogging = newValue
  77. end function
  78. function get_loggingLevel()
  79. get_loggingLevel = loggingLevel
  80. end function
  81. function put_loggingLevel(newValue)
  82. loggingLevel = newValue
  83. end function
  84. function get_statusOK()
  85. get_statusOK = statusOK
  86. end function
  87. function put_statusOK(newValue)
  88. statusOK = newValue
  89. end function
  90. function get_testName()
  91. get_testName = testName
  92. end function
  93. function put_testName(newValue)
  94. testName = newValue
  95. end function
  96. function get_appendLog()
  97. get_appendLog = appendLog
  98. end function
  99. function put_appendLog(newValue)
  100. appendLog = newValue
  101. end function
  102. function writeToLog(strText, iLevel)
  103. on error resume next
  104. EnsureLogFileCreated
  105. if enableLogging AND (iLevel <= loggingLevel) then
  106. if Not(IsNull(file)) then file.WriteLine (strText)
  107. end if
  108. Err.Clear
  109. end function
  110. function writeErrorToLog(err, strText)
  111. on error resume next
  112. statusOK = false
  113. EnsureLogFileCreated
  114. if IsNull(err) then
  115. strText = "ERROR: " & strText
  116. elseif err <> 0 then
  117. strText = "ERROR: [0x" & Hex(err.Number) & " - " & err.Description & _
  118. " - " & Err.Source & "] " & strText
  119. end if
  120. if enableLogging then
  121. if Not(IsNull(file)) then file.WriteLine (strText)
  122. end if
  123. err.clear
  124. end function
  125. function testComplete
  126. on error resume next
  127. EnsureLogFileCreated
  128. if enableLogging then
  129. if Not(IsNull(file)) then
  130. file.WriteLine
  131. file.WriteLine ("********************************")
  132. if statusOK then
  133. file.WriteLine testName & ": PASS"
  134. else
  135. file.WriteLine testName & ": FAIL"
  136. end if
  137. file.WriteLine ("********************************")
  138. file.WriteLine
  139. end if
  140. end if
  141. end function
  142. function testStart
  143. on error resume next
  144. EnsureLogFileCreated
  145. if enableLogging then
  146. if Not(IsNull(file)) then
  147. file.WriteLine
  148. file.WriteLine ("********************************")
  149. file.WriteLine "Starting test " & testName
  150. file.WriteLine ("********************************")
  151. file.WriteLine
  152. end if
  153. end if
  154. end function
  155. function DisplayValue (obj, p)
  156. on error resume next
  157. writeToLog "", 2
  158. writeToLog ">> Value of " & p, 2
  159. set prop = obj.Properties_(p)
  160. if Not(IsObject(prop)) then
  161. writeToLog " <null>", 2
  162. elseif IsNull (prop.Value) then
  163. writeToLog " <null>", 2
  164. elseif IsArray (prop.Value) then
  165. str = " ["
  166. v = prop.Value
  167. for i = LBound(v) to UBound(v)
  168. if wbemCimtypeObject = prop.CIMtype then
  169. str = str + v(i).GetObjectText_
  170. else
  171. str = str & v(i)
  172. end if
  173. if i < UBound(v) then str = str & ", "
  174. next
  175. str = str & "]"
  176. writeToLog str, 2
  177. else
  178. v = prop.Value
  179. if wbemCimtypeObject = prop.CIMtype then
  180. writeToLog v.GetObjectText_, 2
  181. else
  182. writeToLog v, 2
  183. end if
  184. end if
  185. writeToLog "<< Value", 2
  186. end function
  187. function VerifyValue (v1, v2)
  188. on error resume next
  189. if (IsNull(v1) AND Not(IsNull(v2))) OR (Not(IsNull(v1)) AND IsNull(v2)) then
  190. writeErrorToLog err, "Value is incorrect as one is null "
  191. elseif IsNull(v1) AND IsNull(v2) then
  192. writeToLog "Value is correct", 2
  193. else
  194. l1 = LBound(v1)
  195. l2 = LBound(v2)
  196. u1 = UBound(v1)
  197. u2 = UBound(v2)
  198. if l1 <> l2 OR u1 <> u2 then
  199. writeErrorToLog err, "Value is incorrect " & l1 & " " & l2 & " " & u1 & " " & u2
  200. else
  201. Dim i
  202. match = true
  203. for i = l1 to u1
  204. if IsObject(v1(i)) then
  205. if Not(v1(i).compareto_ (v2(i))) then
  206. match = false
  207. exit for
  208. end if
  209. else
  210. if v1(i) <> v2(i) then
  211. match = false
  212. exit for
  213. end if
  214. end if
  215. next
  216. if match then
  217. writeToLog "Value is correct", 2
  218. else
  219. writeErrorToLog err, "Value is incorrect on index " & i
  220. end if
  221. end if
  222. end if
  223. end function
  224. '*******************************************
  225. ' Private methods
  226. '*******************************************
  227. Sub EnsureLogFileCreated
  228. on error resume next
  229. set fso = CreateObject("Scripting.FileSystemObject")
  230. if appendLog then
  231. mode = 8
  232. else
  233. mode = 2
  234. end if
  235. set file = fso.OpenTextFile (logFile, mode, true)
  236. End Sub
  237. ]]>
  238. </script>
  239. </component>