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.
168 lines
4.7 KiB
168 lines
4.7 KiB
<!-- *****************************************************************
|
|
'
|
|
' objtext.wsf
|
|
'
|
|
' Purpose: test object text functionality
|
|
'
|
|
' Parameters: none
|
|
'
|
|
' Returns: 0 - success
|
|
' 1 - failure
|
|
'
|
|
'****************************************************************** -->
|
|
|
|
<job id="ObjectTextExample">
|
|
<reference object="WbemScripting.SWbemLocator" version="1.2"/>
|
|
<script language="VBScript">
|
|
|
|
on error resume next
|
|
set scriptHelper = CreateObject("WMIScriptHelper.WSC")
|
|
scriptHelper.logFile = "c:\temp\objtext.txt"
|
|
scriptHelper.loggingLevel = 3
|
|
scriptHelper.testName = "OBJECTTEXT"
|
|
scriptHelper.testStart
|
|
|
|
'*****************************
|
|
'Get an object
|
|
'*****************************
|
|
set disk = GetObject("winmgmts:win32_logicaldisk")
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to get disk?"
|
|
else
|
|
scriptHelper.writeToLog "Disk retrieved correctly", 2
|
|
end if
|
|
|
|
'*****************************
|
|
'Get the DMTF XML text
|
|
'*****************************
|
|
cimXmlStr = disk.GetText_ (wbemObjectTextFormatCIMDTD20)
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to get DMTF XML text"
|
|
else
|
|
scriptHelper.writeToLog "DMTF XML text retrieved correctly", 2
|
|
scriptHelper.writeToLog "", 2
|
|
scriptHelper.writeToLog "*************************************************",2
|
|
scriptHelper.writeToLog cimXmlStr,2
|
|
scriptHelper.writeToLog "*************************************************",2
|
|
scriptHelper.writeToLog "", 2
|
|
end if
|
|
|
|
'*****************************
|
|
'Get the WMI20 XML text
|
|
'*****************************
|
|
wmi20XmlStr = disk.GetText_ (wbemObjectTextFormatWMIDTD20)
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to get WMI 2.0 XML text"
|
|
else
|
|
scriptHelper.writeToLog "WMI 2.0 XML text retrieved correctly", 2
|
|
scriptHelper.writeToLog "", 2
|
|
scriptHelper.writeToLog "*************************************************",2
|
|
scriptHelper.writeToLog wmi20XmlStr,2
|
|
scriptHelper.writeToLog "*************************************************",2
|
|
scriptHelper.writeToLog "", 2
|
|
end if
|
|
|
|
'*****************************
|
|
'Get a new base class
|
|
'*****************************
|
|
set newClass = GetObject("winmgmts:root\default").Get ()
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to get new base class"
|
|
else
|
|
scriptHelper.writeToLog "Base class retrieved correctly", 2
|
|
end if
|
|
|
|
'*****************************
|
|
'Get a new XML document
|
|
'*****************************
|
|
set xml = CreateObject("Microsoft.XMLDOM")
|
|
xml.async = false
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to create XML document"
|
|
else
|
|
scriptHelper.writeToLog "XML document created correctly", 2
|
|
end if
|
|
|
|
'*****************************
|
|
'Get the base class XML representation
|
|
'*****************************
|
|
xmlStr = newClass.GetText_ (wbemObjectTextWMIDTD20)
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to get XML representation"
|
|
else
|
|
scriptHelper.writeToLog "XML representation retrieved OK", 2
|
|
end if
|
|
|
|
'*****************************
|
|
'Load the XML into the document
|
|
'*****************************
|
|
xml.loadXML xmlStr
|
|
if err <> 0 then
|
|
set parseError = xml.parseError
|
|
scriptHelper.writeErrorToLog err, "Error loading XML: " & parseError.errorCode & _
|
|
" - " & parseError.reason
|
|
else
|
|
scriptHelper.writeToLog "XML loaded OK", 2
|
|
end if
|
|
|
|
'*****************************
|
|
'Set the class name
|
|
'*****************************
|
|
set classNode = xml.SelectSingleNode ("*/CLASS")
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Error in selecting node"
|
|
else
|
|
scriptHelper.writeToLog "Node selected OK", 2
|
|
end if
|
|
|
|
classNode.attributes ("NAME").nodeValue = "Foo"
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Error in setting attribute value"
|
|
else
|
|
scriptHelper.writeToLog "Set attribute OK", 2
|
|
end if
|
|
|
|
|
|
'*****************************
|
|
'Reload the changed XML into the WMI object
|
|
'*****************************
|
|
newClass.SetFromText_ xml.xml, wbemObjectTextWMIDTD20
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Error reloading object from XML"
|
|
else
|
|
scriptHelper.writeToLog "Reloading object from XML OK", 2
|
|
end if
|
|
|
|
'*****************************
|
|
'Check the class name
|
|
'*****************************
|
|
if "Foo" <> newClass.Path_.Class then
|
|
scriptHelper.writeErrorToLog null, "Class not set correctly"
|
|
else
|
|
scriptHelper.writeToLog "Class name set correctly", 2
|
|
end if
|
|
|
|
'*****************************
|
|
'Save it
|
|
'*****************************
|
|
newClass.Put_
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Error saving class"
|
|
else
|
|
scriptHelper.writeToLog "Saved class OK", 2
|
|
end if
|
|
|
|
scriptHelper.testComplete
|
|
|
|
if scriptHelper.statusOK then
|
|
WScript.Echo "PASS"
|
|
WScript.Quit 0
|
|
else
|
|
WScript.Echo "FAIL"
|
|
WScript.Quit 1
|
|
end if
|
|
|
|
</script>
|
|
</job>
|
|
|
|
|