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.
286 lines
7.3 KiB
286 lines
7.3 KiB
<!--
|
|
******************************************************************
|
|
'
|
|
' put.wsf
|
|
'
|
|
' Purpose: test Put functionality
|
|
'
|
|
' Parameters: none
|
|
'
|
|
' Returns: 0 - success
|
|
' 1 - failure
|
|
'
|
|
'*****************************************************************
|
|
-->
|
|
|
|
<job id="WMI Put Test">
|
|
<reference object="WbemScripting.SWbemLocator" version="1.2"/>
|
|
<script language="VBScript">
|
|
|
|
on error resume next
|
|
|
|
set scriptHelper = CreateObject("WMIScriptHelper.WSC")
|
|
scriptHelper.logFile = "c:\temp\put.txt"
|
|
scriptHelper.loggingLevel = 3
|
|
scriptHelper.testName = "WMI Put"
|
|
scriptHelper.testStart
|
|
|
|
dim l
|
|
dim nsDefault
|
|
dim nsCimv2
|
|
dim nsRemote
|
|
|
|
TestPreamble
|
|
TestCreation
|
|
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.SWbemLocator")
|
|
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 nsDefault = 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 = nsDefault.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 = "PUT000TEST"
|
|
|
|
' 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
|
|
set path = newClass.Put_
|
|
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to save class"
|
|
else
|
|
scriptHelper.writeToLog "Successful save of class", 2
|
|
end if
|
|
|
|
if path.Path <> "\\.\root\default:PUT000TEST" then
|
|
scriptHelper.writeErrorToLog null, "Unexpected path returned"
|
|
else
|
|
scriptHelper.writeToLog "Path returned from class put is OK", 2
|
|
end if
|
|
|
|
' Save the class in another namespace
|
|
set nsCimv2 = l.ConnectServer (,"root\cimv2")
|
|
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to connect to root\cimv2"
|
|
else
|
|
scriptHelper.writeToLog "Successful connection to root\cimv2", 2
|
|
end if
|
|
|
|
set path = nsCimv2.Put (newClass)
|
|
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to save class"
|
|
else
|
|
scriptHelper.writeToLog "Successful save of class", 2
|
|
end if
|
|
|
|
if path.Path <> "\\.\root\cimv2:PUT000TEST" then
|
|
scriptHelper.writeErrorToLog null, "Unexpected path returned"
|
|
else
|
|
scriptHelper.writeToLog "Path returned from class put is OK", 2
|
|
end if
|
|
|
|
' Save the class in a remote namespace
|
|
set nsRemote = l.ConnectServer ("alanbos2", "root\default")
|
|
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to connect to \\alanbos2\root\default"
|
|
else
|
|
scriptHelper.writeToLog "Successful connection to \\alanbos2\root\default", 2
|
|
end if
|
|
|
|
' Save the class in a remote namespace
|
|
set path = nsRemote.Put (newClass)
|
|
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to save class"
|
|
else
|
|
scriptHelper.writeToLog "Successful save of class", 2
|
|
end if
|
|
|
|
if path.Path <> "\\alanbos2\root\default:PUT000TEST" then
|
|
scriptHelper.writeErrorToLog null, "Unexpected path returned"
|
|
else
|
|
scriptHelper.writeToLog "Path returned from class put is OK", 2
|
|
end if
|
|
|
|
|
|
End Sub
|
|
|
|
'******************************************************************
|
|
'
|
|
' TestCreation
|
|
'
|
|
' Purpose: Check paths of new instances are OK
|
|
'
|
|
'*****************************************************************
|
|
|
|
Sub TestCreation
|
|
|
|
on error resume next
|
|
|
|
' Regular SpawnInstance
|
|
|
|
set myInstance = nsDefault.Get ("PUT000TEST").SpawnInstance_
|
|
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to create instance "
|
|
else
|
|
scriptHelper.writeToLog "Successful creation of instance", 2
|
|
end if
|
|
|
|
myInstance.p0 = 1
|
|
set path = myInstance.Put_
|
|
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to save instance"
|
|
else
|
|
scriptHelper.writeToLog "Successful save of instance", 2
|
|
end if
|
|
|
|
if (0 = StrComp(path.Path, "\\.\root\default:PUT000TEST.p0=1", vbTextCompare)) Or _
|
|
(0 = StrComp(path.Path, "\\alanbos4\root\default:PUT000TEST.p0=1", vbTextCompare)) then
|
|
scriptHelper.writeToLog "Path returned on instance put to root\default is OK", 2
|
|
else
|
|
scriptHelper.writeErrorToLog null, "Unexpected path returned on instance put to root\default"
|
|
end if
|
|
|
|
' Open an object
|
|
set myInstance = l.ConnectServer (,"root\cimv2").Get("PUT000TEST").SpawnInstance_
|
|
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to create instance"
|
|
else
|
|
scriptHelper.writeToLog "Successful creation of instance", 2
|
|
end if
|
|
|
|
myInstance.p0 = 23
|
|
set path = myInstance.Put_
|
|
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to save instance"
|
|
else
|
|
scriptHelper.writeToLog "Successful save of instance", 2
|
|
end if
|
|
|
|
if (0 = StrComp(path.Path, "\\.\root\cimv2:PUT000TEST.p0=23", vbTextCompare)) Or _
|
|
(0 = StrComp(path.Path, "\\alanbos4\root\cimv2:PUT000TEST.p0=23", vbTextCompare)) then
|
|
scriptHelper.writeToLog "Path returned on instance put to \\.\root\cimv2 is OK", 2
|
|
else
|
|
scriptHelper.writeErrorToLog null, "Unexpected path returned on instance put to \\.\root\cimv2 [" & path.Path & "]"
|
|
end if
|
|
|
|
' Save to a different namespace
|
|
|
|
set myInstance = nsRemote.Get("PUT000TEST").SpawnInstance_
|
|
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to get instance"
|
|
else
|
|
scriptHelper.writeToLog "Successful get of instance", 2
|
|
end if
|
|
|
|
myInstance.p0 = 77
|
|
set path = nsRemote.Put (myInstance)
|
|
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to save instance"
|
|
else
|
|
scriptHelper.writeToLog "Successful save of instance", 2
|
|
end if
|
|
|
|
if (0 = StrComp(path.Path, "\\alanbos2\root\default:PUT000TEST.p0=77", vbTextCompare)) then
|
|
scriptHelper.writeToLog "Path returned on instance put to \\alanbos2\root\default is OK", 2
|
|
else
|
|
scriptHelper.writeErrorToLog null, "Unexpected path returned on instance put to \\alanbos2\root\default [" & path.Path & "]"
|
|
end if
|
|
|
|
|
|
End Sub
|
|
|
|
'******************************************************************
|
|
'
|
|
' TestPostamble
|
|
'
|
|
' Purpose: Create some objects for this test
|
|
'
|
|
'*****************************************************************
|
|
|
|
Sub TestPostamble
|
|
|
|
on error resume next
|
|
|
|
' Clean up
|
|
nsDefault.Delete ("PUT000TEST")
|
|
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to delete class in root\default"
|
|
else
|
|
scriptHelper.writeToLog "Successful delete of class in root\default", 2
|
|
end if
|
|
|
|
nsCimv2.Delete ("PUT000TEST")
|
|
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to delete class in root\cimv2"
|
|
else
|
|
scriptHelper.writeToLog "Successful delete of class in root\cimv2", 2
|
|
end if
|
|
|
|
nsRemote.Delete ("PUT000TEST")
|
|
|
|
End Sub
|
|
</script>
|
|
</job>
|