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.
 
 
 
 
 
 

191 lines
4.1 KiB

<!--
******************************************************************
'
' copy.wsf
'
' Purpose: test object copying
'
' Parameters: none
'
' Returns: 0 - success
' 1 - failure
'
'*****************************************************************
-->
<job id="WMI Copy Test">
<reference object="WbemScripting.SWbemLocator" version="1.2"/>
<script language="VBScript">
on error resume next
set scriptHelper = CreateObject("WMIScriptHelper.WSC")
scriptHelper.logFile = "c:\temp\copy.txt"
scriptHelper.loggingLevel = 3
scriptHelper.testName = "WMI Copy"
scriptHelper.testStart
dim l
dim ns
TestPreamble
TestCopy
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 = "COPY000TEST"
' 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 ("COPY000TEST").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
End Sub
'******************************************************************
'
' TestPostamble
'
' Purpose: Create some objects for this test
'
'*****************************************************************
Sub TestPostamble
on error resume next
' Clean up
ns.Delete ("COPY000TEST")
if err <> 0 then
scriptHelper.writeErrorToLog err, "Failed to delete classes"
else
scriptHelper.writeToLog "Successful delete of classes", 2
end if
End Sub
'******************************************************************
'
' TestCopy
'
' Purpose: test SWbemServicesEx vector functionality
'
'*****************************************************************
Sub TestCopy
on error resume next
scriptHelper.writeToLog ">>>", 2
scriptHelper.writeToLog ">>> TestCopy", 2
scriptHelper.writeToLog ">>>", 2
' Open the instance to be copied
set oInstance = ns.Get ("COPY000TEST=1")
if err <> 0 then
scriptHelper.writeErrorToLog err, "Failed to open instance"
else
scriptHelper.writeToLog "Successful opening of instance", 2
end if
'Now copy it
set nInstance = oInstance.CopyTo_ ("COPY000TEST=2")
if err <> 0 then
scriptHelper.writeErrorToLog err, "Failed to copy instance"
else
scriptHelper.writeToLog "Successful copy of instance: " & nInstance.Path_.Path, 2
end if
scriptHelper.writeToLog "<<<", 2
scriptHelper.writeToLog "<<< TestCopy", 2
scriptHelper.writeToLog "<<<", 2
End Sub
</script>
</job>