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

<?xml version="1.0"?>
<component>
<?component error="true" debug="true"?>
<comment>This is a reusable scripted logging and status control</comment>
<registration
description="WMIScriptHelper"
progid="WMIScriptHelper.WSC"
version="1.00"
classid="{db547feb-ec59-4004-968c-3920c88f3154}"
>
</registration>
<public>
<property name="logFile">
<get/>
<put/>
</property>
<property name="enableLogging">
<get/>
<put/>
</property>
<property name="loggingLevel">
<get/>
<put/>
</property>
<property name="statusOK">
<get/>
<put/>
</property>
<property name="testName">
<get/>
<put/>
</property>
<property name="appendLog">
<get/>
<put/>
</property>
<method name="writeToLog">
<PARAMETER name="strText"/>
<PARAMETER name="iLevel"/>
</method>
<method name="writeErrorToLog">
<PARAMETER name="err"/>
<PARAMETER name="strText"/>
</method>
<method name="testStart"/>
<method name="testComplete"/>
<method name="DisplayValue"/>
<method name="VerifyValue"/>
</public>
<implements type="Behavior" id="Behavior"/>
<script language="VBScript">
<![CDATA[
dim logFile
logFile = "c:\temp\wmiscrp.txt"
dim enableLogging
enableLogging = true
dim loggingLevel
loggingLevel = 1
dim statusOK
statusOK = true
dim testName
testName = "Test"
dim appendLog
appendLog = false
dim file
function get_logFile()
get_logFile = logFile
end function
function put_logFile(newValue)
logFile = newValue
end function
function get_enableLogging()
get_enableLogging = enableLogging
end function
function put_enableLogging(newValue)
enableLogging = newValue
end function
function get_loggingLevel()
get_loggingLevel = loggingLevel
end function
function put_loggingLevel(newValue)
loggingLevel = newValue
end function
function get_statusOK()
get_statusOK = statusOK
end function
function put_statusOK(newValue)
statusOK = newValue
end function
function get_testName()
get_testName = testName
end function
function put_testName(newValue)
testName = newValue
end function
function get_appendLog()
get_appendLog = appendLog
end function
function put_appendLog(newValue)
appendLog = newValue
end function
function writeToLog(strText, iLevel)
on error resume next
EnsureLogFileCreated
if enableLogging AND (iLevel <= loggingLevel) then
if Not(IsNull(file)) then file.WriteLine (strText)
end if
Err.Clear
end function
function writeErrorToLog(err, strText)
on error resume next
statusOK = false
EnsureLogFileCreated
if IsNull(err) then
strText = "ERROR: " & strText
elseif err <> 0 then
strText = "ERROR: [0x" & Hex(err.Number) & " - " & err.Description & _
" - " & Err.Source & "] " & strText
end if
if enableLogging then
if Not(IsNull(file)) then file.WriteLine (strText)
end if
err.clear
end function
function testComplete
on error resume next
EnsureLogFileCreated
if enableLogging then
if Not(IsNull(file)) then
file.WriteLine
file.WriteLine ("********************************")
if statusOK then
file.WriteLine testName & ": PASS"
else
file.WriteLine testName & ": FAIL"
end if
file.WriteLine ("********************************")
file.WriteLine
end if
end if
end function
function testStart
on error resume next
EnsureLogFileCreated
if enableLogging then
if Not(IsNull(file)) then
file.WriteLine
file.WriteLine ("********************************")
file.WriteLine "Starting test " & testName
file.WriteLine ("********************************")
file.WriteLine
end if
end if
end function
function DisplayValue (obj, p)
on error resume next
writeToLog "", 2
writeToLog ">> Value of " & p, 2
set prop = obj.Properties_(p)
if Not(IsObject(prop)) then
writeToLog " <null>", 2
elseif IsNull (prop.Value) then
writeToLog " <null>", 2
elseif IsArray (prop.Value) then
str = " ["
v = prop.Value
for i = LBound(v) to UBound(v)
if wbemCimtypeObject = prop.CIMtype then
str = str + v(i).GetObjectText_
else
str = str & v(i)
end if
if i < UBound(v) then str = str & ", "
next
str = str & "]"
writeToLog str, 2
else
v = prop.Value
if wbemCimtypeObject = prop.CIMtype then
writeToLog v.GetObjectText_, 2
else
writeToLog v, 2
end if
end if
writeToLog "<< Value", 2
end function
function VerifyValue (v1, v2)
on error resume next
if (IsNull(v1) AND Not(IsNull(v2))) OR (Not(IsNull(v1)) AND IsNull(v2)) then
writeErrorToLog err, "Value is incorrect as one is null "
elseif IsNull(v1) AND IsNull(v2) then
writeToLog "Value is correct", 2
else
l1 = LBound(v1)
l2 = LBound(v2)
u1 = UBound(v1)
u2 = UBound(v2)
if l1 <> l2 OR u1 <> u2 then
writeErrorToLog err, "Value is incorrect " & l1 & " " & l2 & " " & u1 & " " & u2
else
Dim i
match = true
for i = l1 to u1
if IsObject(v1(i)) then
if Not(v1(i).compareto_ (v2(i))) then
match = false
exit for
end if
else
if v1(i) <> v2(i) then
match = false
exit for
end if
end if
next
if match then
writeToLog "Value is correct", 2
else
writeErrorToLog err, "Value is incorrect on index " & i
end if
end if
end if
end function
'*******************************************
' Private methods
'*******************************************
Sub EnsureLogFileCreated
on error resume next
set fso = CreateObject("Scripting.FileSystemObject")
if appendLog then
mode = 8
else
mode = 2
end if
set file = fso.OpenTextFile (logFile, mode, true)
End Sub
]]>
</script>
</component>