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.
 
 
 
 
 
 

690 lines
20 KiB

<!--
******************************************************************
'
' deletevalues.wsf
'
' Purpose: test SWbemPropertyEx::DeleteValues
'
' Parameters: none
'
' Returns: 0 - success
' 1 - failure
'
'*****************************************************************
-->
<job id="WMI DeleteValues Test">
<reference object="WbemScripting.SWbemLocator" version="1.2"/>
<script language="VBScript">
on error resume next
set scriptHelper = CreateObject("WMIScriptHelper.WSC")
scriptHelper.logFile = "c:\temp\deletevalues.txt"
scriptHelper.loggingLevel = 3
scriptHelper.testName = "WMI DeleteValues"
scriptHelper.testStart
dim ns
dim newClass
dim sysClass, disk, process
' Get some useful classes for embedded objects
set sysClass = GetObject("winmgmts:__SystemClass")
set disk = GetObject("winmgmts:Win32_logicaldisk")
set process = GetObject("winmgmts:Win32_process")
if err <> 0 then
scriptHelper.writeErrorToLog err, "Failed to get utility classes"
else
scriptHelper.writeToLog "Successful retrieval of utility classes", 2
end if
' Connect to the namespace
set ns = GetObject("winmgmts:root\default")
if err <> 0 then
scriptHelper.writeErrorToLog err, "Failed to connect to root\default"
else
scriptHelper.writeToLog "Successful connection to root\default", 2
end if
'Make a new class
set newClass = ns.Get
if err <> 0 then
scriptHelper.writeErrorToLog err, "Failed to get empty class"
else
scriptHelper.writeToLog "Successful retrieval of empty class", 2
end if
newClass.Path_.Class = "DELETEVALUES000TEST"
' Add a non-array property (uint32)
set p0 = newClass.Properties_.Add ("p0", 19)
p0 = 251
' Add some array properties, one for each type
set p = newClass.Properties_.Add ("pSint8", wbemCimtypeSint8, true)
p.Value = Array (-1, 0, 3, 1, 2, 3)
set p = newClass.Properties_.Add ("pUint8", wbemCimtypeUint8, true)
p.Value = Array (0, 1, 123, 222, 1, 0, 1)
set p = newClass.Properties_.Add ("pSint16", wbemCimtypeSint16, true)
p.Value = Array (-1, 0, 1, 3, -4)
set p = newClass.Properties_.Add ("pUint16", wbemCimtypeUint16, true)
p.Value = Array (0, 1, 65535, 23)
set p = newClass.Properties_.Add ("pSint32", wbemCimtypeSint32, true)
p.Value = Array (-1, 0, 1, 2, 89)
set p = newClass.Properties_.Add ("pUint32", wbemCimtypeUint32, true)
p.Value = Array (0, 1, 65535, 26)
set p = newClass.Properties_.Add ("pSint64", wbemCimtypeSint64, true)
p.Value = Array ("-1", "0", "1", "2", "11")
set p = newClass.Properties_.Add ("pUint64", wbemCimtypeUint64, true)
p.Value = Array ("0", "1", "65535", "123", "65535")
set p = newClass.Properties_.Add ("pReal32", wbemCimtypeReal32, true)
p.Value = Array (1.2, -123.456, 23.004, 34.44)
set p = newClass.Properties_.Add ("pReal64", wbemCimtypeReal64, true)
p.Value = Array (1.2, -123.456, 23.004, 332.1)
set p = newClass.Properties_.Add ("pBoolean", wbemCimtypeBoolean, true)
p.Value = Array (true, false, true, true)
set p = newClass.Properties_.Add ("pString", wbemCimtypeString, true)
p.Value = Array ("I", "have", "but", "an", "hour", "Obey", "the", "time")
set p = newClass.Properties_.Add ("pDatetime", wbemCimtypeDatetime, true)
p.Value = Array ("20000120195632.000000-480", _
"20000120195632.000000+480", "20000120195632.000000-480", "20000120195632.000000-480")
set p = newClass.Properties_.Add ("pReference", wbemCimtypeReference, true)
p.Value = Array ("root\cimv2:win32_logicaldisk", _
"root\default:__cimomidentification=@", "root\default:__cimomidentification=@", _
"root\cimv2:win32_logicaldisk")
set p = newClass.Properties_.Add ("pChar16", wbemCimtypeChar16, true)
p.Value = Array (34, 35, 36, 37)
set p = newClass.Properties_.Add ("pObject", wbemCimtypeObject, true)
p.Value = Array (sysClass, disk, process, disk)
if err <> 0 then
scriptHelper.writeErrorToLog err, "Failed to define class"
else
scriptHelper.writeToLog "Successful definition of class", 2
end if
' Save the class
newClass.Put_
if err <> 0 then
scriptHelper.writeErrorToLog err, "Failed to save class"
else
scriptHelper.writeToLog "Successful save of class", 2
end if
' Get it back
set newClass = ns.Get ("DELETEVALUES000TEST")
if err <> 0 then
scriptHelper.writeErrorToLog err, "Failed to get class"
else
scriptHelper.writeToLog "Successful get of class", 2
end if
' now test each property type
TestUint8
TestSint8
TestUint16
TestSint16
TestUint32
TestSint32
TestUint64
TestSint64
TestReal32
TestReal64
TestBoolean
TestString
TestDatetime
TestReference
TestChar16
TestObject
' Save the class
newClass.Put_
if err <> 0 then
scriptHelper.writeErrorToLog err, "Failed to save class"
else
scriptHelper.writeToLog "Successful save of class", 2
end if
' Clean up
newClass.Delete_
if err <> 0 then
scriptHelper.writeErrorToLog err, "Failed to delete class"
else
scriptHelper.writeToLog "Successful delete of class", 2
end if
scriptHelper.testComplete
if scriptHelper.statusOK then
WScript.Echo "PASS"
WScript.Quit 0
else
WScript.Echo "FAIL"
WScript.Quit 1
end if
'****************************************************************
'*
'* TestUint8
'* =========
'*
'* Test AddValues for uint8 arrays
'*
'****************************************************************
Sub TestUint8
on error resume next
' Try a delete of first match
set pUint8 = newClass.Properties_("pUint8")
pUint8.DeleteValues 123
scriptHelper.DisplayValue newClass, "pUint8"
scriptHelper.VerifyValue pUint8.Value, Array (0, 1, 222, 1, 0, 1)
' Try a delete of all matches
pUint8.DeleteValues Array (0, 1), wbemDeleteValuesDeleteAllMatches
scriptHelper.DisplayValue newClass, "pUint8"
scriptHelper.VerifyValue pUint8.Value, Array (222)
' Try a delete of all
pUint8.DeleteValues , wbemDeleteValuesDeleteAll
scriptHelper.DisplayValue newClass, "pUint8"
scriptHelper.VerifyValue pUint8.Value, Array ()
End Sub
'****************************************************************
'*
'* TestSint8
'* =========
'*
'* Test AddValues for sint8 arrays
'*
'****************************************************************
Sub TestSint8
on error resume next
' Try a delete of first match
set pSint8 = newClass.Properties_("pSint8")
pSint8.DeleteValues Array (0, 22, 3)
scriptHelper.DisplayValue newClass, "pSint8"
scriptHelper.VerifyValue pSint8.Value, Array (-1, 3, 1, 2, 3)
' Try a delete of all matches within a range
pSint8.DeleteValues Array (3, 1), wbemDeleteValuesDeleteAllMatches, 1, 2
scriptHelper.DisplayValue newClass, "pSint8"
scriptHelper.VerifyValue pSint8.Value, Array (-1, 2, 3)
' Try a delete of all
pSint8.DeleteValues , wbemDeleteValuesDeleteAll
scriptHelper.DisplayValue newClass, "pSint8"
scriptHelper.VerifyValue pSint8.Value, Array ()
End Sub
'****************************************************************
'*
'* TestString
'* ============
'*
'* Test AddValues for string arrays
'*
'****************************************************************
Sub TestString
on error resume next
' Try a delete of first match
set pString = newClass.Properties_("pString")
pString.DeleteValues "Obey", wbemDeleteValuesDeleteFirstMatch, 5, -1
scriptHelper.DisplayValue newClass, "pString"
scriptHelper.VerifyValue pString.Value, Array ("I", "have", "but", "an", "hour", "the", "time")
' Try a delete of all matches within a range
pString.DeleteValues Array ("I", "You", "Me", "the"), wbemDeleteValuesDeleteAllMatches, 0, 5
scriptHelper.DisplayValue newClass, "pString"
scriptHelper.VerifyValue pString.Value, Array ("have", "but", "an", "hour", "time")
' Try a delete of all
pString.DeleteValues , wbemDeleteValuesDeleteAll
scriptHelper.DisplayValue newClass, "pString"
scriptHelper.VerifyValue pString.Value, Array ()
End Sub
'****************************************************************
'*
'* TestUint16
'* ==========
'*
'* Test AddValues for uint16 arrays
'*
'****************************************************************
Sub TestUint16
on error resume next
' Try a delete of first match
set pUint16 = newClass.Properties_("pUint16")
pUint16.DeleteValues Array (2, 3, 4, 54, 23), wbemDeleteValuesDeleteFirstMatch, 0, -1
scriptHelper.DisplayValue newClass, "pUint16"
scriptHelper.VerifyValue pUint16.Value, Array (0, 1, 65535)
' Try a delete of all matches within a range
pUint16.DeleteValues Array (0, 65535), wbemDeleteValuesDeleteAllMatches
scriptHelper.DisplayValue newClass, "pUint16"
scriptHelper.VerifyValue pUint16.Value, Array (1)
' Try a delete of all
pUint16.DeleteValues , wbemDeleteValuesDeleteAll
scriptHelper.DisplayValue newClass, "pUint16"
scriptHelper.VerifyValue pUint16.Value, Array ()
End Sub
'****************************************************************
'*
'* TestSint16
'* ==========
'*
'* Test AddValues for sint16 arrays
'*
'****************************************************************
Sub TestSint16
on error resume next
' Try a delete of first match
set pSint16 = newClass.Properties_("pSint16")
pSint16.DeleteValues -1, wbemDeleteValuesDeleteFirstMatch
scriptHelper.DisplayValue newClass, "pSint16"
scriptHelper.VerifyValue pSint16.Value, Array (0, 1, 3, -4)
' Try a delete of all matches within a range
pSint16.DeleteValues Array (0, 65535, -4), wbemDeleteValuesDeleteAllMatches
scriptHelper.DisplayValue newClass, "pSint16"
scriptHelper.VerifyValue pSint16.Value, Array (1, 3)
' Try a delete of all
pSint16.DeleteValues , wbemDeleteValuesDeleteAll
scriptHelper.DisplayValue newClass, "pSint16"
scriptHelper.VerifyValue pSint16.Value, Array ()
End Sub
'****************************************************************
'*
'* TestUint32
'* ==========
'*
'* Test AddValues for uint32 arrays
'*
'****************************************************************
Sub TestUint32
on error resume next
' Try a delete of first match
set pUint32 = newClass.Properties_("pUint32")
pUint32.DeleteValues 1, wbemDeleteValuesDeleteFirstMatch
scriptHelper.DisplayValue newClass, "pUint32"
scriptHelper.VerifyValue pUint32.Value, Array (0, 65535, 26)
' Try a delete of all matches within a range
pUint32.DeleteValues Array (0, 65535, -4), wbemDeleteValuesDeleteAllMatches
scriptHelper.DisplayValue newClass, "pUint32"
scriptHelper.VerifyValue pUint32.Value, Array (26)
' Try a delete of all
pUint32.DeleteValues , wbemDeleteValuesDeleteAll
scriptHelper.DisplayValue newClass, "pUint32"
scriptHelper.VerifyValue pUint32.Value, Array ()
End Sub
'****************************************************************
'*
'* TestSint32
'* ==========
'*
'* Test AddValues for sint32 arrays
'*
'****************************************************************
Sub TestSint32
on error resume next
' Try a delete of first match
set pSint32 = newClass.Properties_("pSint32")
pSint32.DeleteValues 11, wbemDeleteValuesDeleteFirstMatch
scriptHelper.DisplayValue newClass, "pSint32"
scriptHelper.VerifyValue pSint32.Value, Array (-1, 0, 1, 2, 89)
' Try a delete of all matches within a range
pSint32.DeleteValues Array (0, 65535, -4, 2, 89), wbemDeleteValuesDeleteAllMatches, 0, 2
scriptHelper.DisplayValue newClass, "pSint32"
scriptHelper.VerifyValue pSint32.Value, Array (-1, 1, 2, 89)
' Try a delete of all
pSint32.DeleteValues , wbemDeleteValuesDeleteAll
scriptHelper.DisplayValue newClass, "pSint32"
scriptHelper.VerifyValue pSint32.Value, Array ()
End Sub
'****************************************************************
'*
'* TestUint64
'* ==========
'*
'* Test AddValues for uint64 arrays
'*
'****************************************************************
Sub TestUint64
on error resume next
' Try a delete of first match
set pUint64 = newClass.Properties_("pUint64")
pUint64.DeleteValues "1", wbemDeleteValuesDeleteFirstMatch
scriptHelper.DisplayValue newClass, "pUint64"
scriptHelper.VerifyValue pUint64.Value, Array ("0", "65535", "123", "65535")
' Try a delete of all matches within a range
pUint64.DeleteValues Array ("65535"), wbemDeleteValuesDeleteAllMatches, 0, 2
scriptHelper.DisplayValue newClass, "pUint64"
scriptHelper.VerifyValue pUint64.Value, Array ("0", "123", "65535")
' Try a delete of all
pUint64.DeleteValues , wbemDeleteValuesDeleteAll
scriptHelper.DisplayValue newClass, "pUint64"
scriptHelper.VerifyValue pUint64.Value, Array ()
End Sub
'****************************************************************
'*
'* TestSint64
'* ==========
'*
'* Test AddValues for sint64 arrays
'*
'****************************************************************
Sub TestSint64
on error resume next
' Try a delete of first match
set pSint64 = newClass.Properties_("pSint64")
pSint64.DeleteValues "21", wbemDeleteValuesDeleteFirstMatch
scriptHelper.DisplayValue newClass, "pSint64"
scriptHelper.VerifyValue pSint64.Value, Array ("-1", "0", "1", "2", "11")
' Try a delete of all matches within a range
pSint64.DeleteValues Array ("-1", "11"), wbemDeleteValuesDeleteAllMatches, 0, 2
scriptHelper.DisplayValue newClass, "pSint64"
scriptHelper.VerifyValue pSint64.Value, Array ("0", "1", "2", "11")
' Try a delete of all
pSint64.DeleteValues , wbemDeleteValuesDeleteAll
scriptHelper.DisplayValue newClass, "pSint64"
scriptHelper.VerifyValue pSint64.Value, Array ()
End Sub
'****************************************************************
'*
'* TestReal32
'* ==========
'*
'* Test AddValues for real32 arrays
'*
'****************************************************************
Sub TestReal32
on error resume next
' NB - note the use of CSng to force constants to be of type
' VT_R4. If we don't do this the supplied constant is of
' type VT_R8 (default for VB and VBScript). This internally
' causes floating point rounding errors when comparing against
' VT_R4's since VT_R4 to VT_R8 conversion is not "pad with 0's".
' Try a delete of first match
set pReal32 = newClass.Properties_("pReal32")
pReal32.DeleteValues CSng(1.2), wbemDeleteValuesDeleteFirstMatch
scriptHelper.DisplayValue newClass, "pReal32"
scriptHelper.VerifyValue pReal32.Value, Array (-123.456, 23.004, 34.44)
' Try a delete of all matches within a range
pReal32.DeleteValues Array (CSng(0), CSng(65535), CSng(34.44)), wbemDeleteValuesDeleteAllMatches
scriptHelper.DisplayValue newClass, "pReal32"
scriptHelper.VerifyValue pReal32.Value, Array (-123.456, 23.004)
' Try a delete of all
pReal32.DeleteValues , wbemDeleteValuesDeleteAll
scriptHelper.DisplayValue newClass, "pReal32"
scriptHelper.VerifyValue pReal32.Value, Array ()
End Sub
'****************************************************************
'*
'* TestReal64
'* ==========
'*
'* Test AddValues for real64 arrays
'*
'****************************************************************
Sub TestReal64
on error resume next
' Try a delete of first match
set pReal64 = newClass.Properties_("pReal64")
pReal64.DeleteValues 332.1, wbemDeleteValuesDeleteFirstMatch
scriptHelper.DisplayValue newClass, "pReal64"
scriptHelper.VerifyValue pReal64.Value, Array (1.2, -123.456, 23.004)
' Try a delete of first match
pReal64.DeleteValues 32.1, wbemDeleteValuesDeleteFirstMatch
scriptHelper.DisplayValue newClass, "pReal64"
scriptHelper.VerifyValue pReal64.Value, Array (1.2, -123.456, 23.004)
' Try a delete of all matches within a range
pReal64.DeleteValues Array (23.004, -123.456), wbemDeleteValuesDeleteAllMatches
scriptHelper.DisplayValue newClass, "pReal64"
scriptHelper.VerifyValue pReal64.Value, Array (1.2)
' Try a delete of all matches within a range
pReal64.DeleteValues Array (23.004, -123.456), wbemDeleteValuesDeleteAllMatches
scriptHelper.DisplayValue newClass, "pReal64"
scriptHelper.VerifyValue pReal64.Value, Array (1.2)
' Try a delete of all
pReal64.DeleteValues , wbemDeleteValuesDeleteAll
scriptHelper.DisplayValue newClass, "pReal64"
scriptHelper.VerifyValue pReal64.Value, Array ()
End Sub
'****************************************************************
'*
'* TestBoolean
'* ===========
'*
'* Test AddValues for boolean arrays
'*
'****************************************************************
Sub TestBoolean
on error resume next
' Try a delete of first match
set pBoolean = newClass.Properties_("pBoolean")
pBoolean.DeleteValues true, wbemDeleteValuesDeleteFirstMatch, 1
scriptHelper.DisplayValue newClass, "pBoolean"
scriptHelper.VerifyValue pBoolean.Value, Array (true, false, true)
' Try a delete of all matches within a range
pBoolean.DeleteValues Array (true, true), wbemDeleteValuesDeleteAllMatches
scriptHelper.DisplayValue newClass, "pBoolean"
scriptHelper.VerifyValue pBoolean.Value, Array (false)
' Try a delete of all
pBoolean.DeleteValues , wbemDeleteValuesDeleteAll
scriptHelper.DisplayValue newClass, "pBoolean"
scriptHelper.VerifyValue pBoolean.Value, Array ()
End Sub
'****************************************************************
'*
'* TestDatetime
'* ============
'*
'* Test AddValues for datetime arrays
'*
'****************************************************************
Sub TestDatetime
on error resume next
' Try a delete of first match
set pDatetime = newClass.Properties_("pDatetime")
pDatetime.DeleteValues "20000120195632.000000-480", wbemDeleteValuesDeleteFirstMatch, 1
scriptHelper.DisplayValue newClass, "pDatetime"
scriptHelper.VerifyValue pDatetime.Value, Array ("20000120195632.000000-480", _
"20000120195632.000000+480", "20000120195632.000000-480")
' Try a delete of all matches within a range
pDatetime.DeleteValues Array ("20000120195632.000000-480", "20000120195632.000000-480"), _
wbemDeleteValuesDeleteAllMatches, , 1
scriptHelper.DisplayValue newClass, "pDatetime"
scriptHelper.VerifyValue pDatetime.Value, Array ("20000120195632.000000+480", "20000120195632.000000-480")
' Try a delete of all
pDatetime.DeleteValues , wbemDeleteValuesDeleteAll
scriptHelper.DisplayValue newClass, "pDatetime"
scriptHelper.VerifyValue pDatetime.Value, Array ()
End Sub
'****************************************************************
'*
'* TestReference
'* =============
'*
'* Test AddValues for reference arrays
'*
'****************************************************************
Sub TestReference
on error resume next
' Try a delete of first match
set pReference = newClass.Properties_("pReference")
pReference.DeleteValues Array ("root\cimv2:win32_logicaldisk", _
"root\default:__cimomidentification=@"), wbemDeleteValuesDeleteFirstMatch
scriptHelper.DisplayValue newClass, "pReference"
scriptHelper.VerifyValue pReference.Value, Array ("root\default:__cimomidentification=@", _
"root\default:__cimomidentification=@", "root\cimv2:win32_logicaldisk")
' Try a delete of all matches within a range
pReference.DeleteValues Array ("root\default:__cimomidentification=@", _
"root\default:__cimomidentification=@", "root\cimv2:win32_logicaldisk"), _
wbemDeleteValuesDeleteAllMatches
scriptHelper.DisplayValue newClass, "pReference"
scriptHelper.VerifyValue pReference.Value, Array ()
' Try a delete of all
pReference.Value = null
pReference.DeleteValues , wbemDeleteValuesDeleteAll
scriptHelper.DisplayValue newClass, "pReference"
scriptHelper.VerifyValue pReference.Value, null
End Sub
'****************************************************************
'*
'* TestChar16
'* ==========
'*
'* Test AddValues for char16 arrays
'*
'****************************************************************
Sub TestChar16
on error resume next
' Try a delete of first match
set pChar16 = newClass.Properties_("pChar16")
pChar16.DeleteValues 35, wbemDeleteValuesDeleteFirstMatch
scriptHelper.DisplayValue newClass, "pChar16"
scriptHelper.VerifyValue pChar16.Value, Array (34, 36, 37)
' Try a delete of all matches within a range
pChar16.DeleteValues Array (35, 36, 34, 42, 43, 44), wbemDeleteValuesDeleteAllMatches
scriptHelper.DisplayValue newClass, "pChar16"
scriptHelper.VerifyValue pChar16.Value, Array (37)
' Try a delete of all
pChar16.DeleteValues , wbemDeleteValuesDeleteAll
scriptHelper.DisplayValue newClass, "pChar16"
scriptHelper.VerifyValue pChar16.Value, Array ()
End Sub
'****************************************************************
'*
'* TestObject
'* ==========
'*
'* Test AddValues for object arrays
'*
'****************************************************************
Sub TestObject
on error resume next
End Sub
</script>
</job>