|
|
<!--
****************************************************************** ' ' vector.wsf ' ' Purpose: test vectors ' ' Parameters: none ' ' Returns: 0 - success ' 1 - failure ' '***************************************************************** -->
<job id="WMI Vector Test"> <reference object="WbemScripting.SWbemLocator" version="1.2"/> <script language="VBScript">
on error resume next
set scriptHelper = CreateObject("WMIScriptHelper.WSC") scriptHelper.logFile = "c:\temp\vector.txt" scriptHelper.loggingLevel = 3 scriptHelper.testName = "WMI Vector" scriptHelper.testStart
dim l dim ns
TestPreamble TestVectorOpen TestPostamble
scriptHelper.testComplete
if scriptHelper.statusOK then WScript.Echo "PASS" WScript.Quit 0 else WScript.Echo "FAIL" WScript.Quit 1 end if
'****************************************************************** ' ' TestPreamble ' ' Purpose: Create some objects for this test ' '*****************************************************************
Sub TestPreamble
on error resume next
' Create a locator set l = CreateObject("WbemScripting.SWbemLocatorEx") if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to create locator" else scriptHelper.writeToLog "Successful creation of locator", 2 end if
' Connect to the namespace set ns = l.ConnectServer (,"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 sub-namespace set newNamespace = ns.Get("__Namespace").SpawnInstance_ if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to get new namespace" else scriptHelper.writeToLog "Successful get of new namespace", 2 end if
newNamespace.Name = "endpoint" newNamespace.Put_
if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to create new namespace" else scriptHelper.writeToLog "Successful creation of new namespace", 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 = "VECTOR000TEST" newClass.Qualifiers_.Add "vector", true
' Add a key property (uint32) set p0 = newClass.Properties_.Add ("p0", wbemCimtypeUint32) p0.Qualifiers_.Add "key", true
' Add the vector pointer set pV = newClass.Properties_.Add ("pV", wbemCimtypeReference) 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 and make an instance set newInstance = ns.Get ("VECTOR000TEST").SpawnInstance_
if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to get new instance" else scriptHelper.writeToLog "Successful get of new instance", 2 end if
' Create an instance newInstance.p0 = 1 newInstance.pV = "\\.\root\default:__Namespace='endpoint'" newInstance.Put_
if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to create endpoint instance" else scriptHelper.writeToLog "Successful creation of instance", 2 end if
' Bind to the new namespace set ns2 = GetObject("winmgmts:root\default\endpoint") set newClass = ns2.Get newClass.Path_.Class = "VECTOR001TEST" newClass.Put_
if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to create class in endpoint namespace" else scriptHelper.writeToLog "Successful creation of class in endpoint namespace", 2 end if
End Sub
'****************************************************************** ' ' TestPostamble ' ' Purpose: Create some objects for this test ' '*****************************************************************
Sub TestPostamble
on error resume next
' Clean up ns.Delete ("__Namespace='endpoint'") ns.Delete ("VECTOR001TEST")
if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to delete classes" else scriptHelper.writeToLog "Successful delete of classes", 2 end if
End Sub
'****************************************************************** ' ' TestVectorOpen ' ' Purpose: test SWbemServicesEx vector functionality ' '*****************************************************************
Sub TestVectorOpen
on error resume next
scriptHelper.writeToLog ">>>", 2 scriptHelper.writeToLog ">>> TestVectorOpen", 2 scriptHelper.writeToLog ">>>", 2
' Open the instance as a vector set vector = ns.Open ("CONTAINER000TEST=1", wbemConnectionFlagOpenVector _ OR wbemConnectionFlagAllowNamespaceTraversal OR wbemConnectionFlagAllowMachineTraversal)
if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to open instance as vector" else scriptHelper.writeToLog "Successful opening of instance as vector", 2 end if
'Just to check we're in the right place, get our class set newClass = vector.Get ("VECTOR001TEST")
if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to get class from dereferenced vector" else scriptHelper.writeToLog "Successful retrieval of class from dereferenced vector: " & newClass.Path_.Path, 2 end if
scriptHelper.writeToLog "<<<", 2 scriptHelper.writeToLog "<<< TestVectorOpen", 2 scriptHelper.writeToLog "<<<", 2
End Sub
</script> </job>
|