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.
 
 
 
 
 
 

215 lines
5.0 KiB

<!--
******************************************************************
'
' move.wsf
'
' Purpose: test object moving
'
' Parameters: none
'
' Returns: 0 - success
' 1 - failure
'
'*****************************************************************
-->
<job id="WMI Move Test">
<reference object="WbemScripting.SWbemLocator" version="1.2"/>
<script language="VBScript">
on error resume next
set scriptHelper = CreateObject("WMIScriptHelper.WSC")
scriptHelper.logFile = "c:\temp\move.txt"
scriptHelper.loggingLevel = 3
scriptHelper.testName = "WMI Move"
scriptHelper.testStart
dim l
dim ns, ns2
TestPreamble
TestMove
'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 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 = "MOVE000TEST"
' Add a key property (uint32)
set p0 = newClass.Properties_.Add ("p0", wbemCimtypeUint32)
p0.Qualifiers_.Add "key", true
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 ("MOVE000TEST").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.Put_
if err <> 0 then
scriptHelper.writeErrorToLog err, "Failed to create instance"
else
scriptHelper.writeToLog "Successful creation of instance", 2
end if
' Save the class in another namespace prior to the move
set ns2 = GetObject("winmgmts:root\cimv2")
set newClass = ns.Get("MOVE000TEST")
ns2.Put (newClass)
if err <> 0 then
scriptHelper.writeErrorToLog err, "Failed to save class in 2nd namespace"
else
scriptHelper.writeToLog "Successful save of class in 2nd namespace", 2
end if
End Sub
'******************************************************************
'
' TestPostamble
'
' Purpose: Create some objects for this test
'
'*****************************************************************
Sub TestPostamble
on error resume next
' Clean up
ns.Delete ("MOVE000TEST")
ns2.Delete ("MOVE000TEST")
if err <> 0 then
scriptHelper.writeErrorToLog err, "Failed to delete classes"
else
scriptHelper.writeToLog "Successful delete of classes", 2
end if
End Sub
'******************************************************************
'
' TestMove
'
' Purpose: test move functionality
'
'*****************************************************************
Sub TestMove
on error resume next
scriptHelper.writeToLog ">>>", 2
scriptHelper.writeToLog ">>> TestMove", 2
scriptHelper.writeToLog ">>>", 2
' Open the instance to be moved
set oInstance = ns.Get ("MOVE000TEST=1")
if err <> 0 then
scriptHelper.writeErrorToLog err, "Failed to open instance"
else
scriptHelper.writeToLog "Successful opening of instance", 2
end if
'Now move it
set nInstance = oInstance.MoveTo_ ("root\cimv2:MOVE000TEST=2")
if err <> 0 then
scriptHelper.writeErrorToLog err, "Failed to move instance"
else
scriptHelper.writeToLog "Successful move of instance: " & nInstance.Path_.Path, 2
end if
' Should have moved "in-place"
if nInstance.Path_.Namespace <> "root\cimv2" then
scriptHelper.writeErrorToLog err, "Wrong namespace [root\cimv2]: " & nInstance.Path_.Namespace
else
scriptHelper.writeToLog "Namespace path is correct: " & nInstance.Path_.Namespace, 2
end if
if nInstance.p0 <> 2 then
scriptHelper.writeErrorToLog err, "Wrong key [2]: " & nInstance.p0
else
scriptHelper.writeToLog "Key is correct: " & nInstance.p0, 2
end if
scriptHelper.writeToLog "<<<", 2
scriptHelper.writeToLog "<<< TestMove", 2
scriptHelper.writeToLog "<<<", 2
End Sub
</script>
</job>