Microsoft KB Archive/309680

= HOW TO: Generate an XML Representation of Your Computer's WMI Objects in Windows 2000 =

Article ID: 309680

Article Last Modified on 10/30/2006

-

APPLIES TO


 * Microsoft Windows 2000 Server

-



This article was previously published under Q309680





IN THIS TASK
SUMMARY
 * Requirements
 * How to Generate an XML Representation of Your WMI Objects



SUMMARY
This step-by-step article describes how to create and run a script that generates an Extensible Markup Language (XML) representation of the Windows Management Instrumentation (WMI) objects on your computer.

Requirements

 * Windows 2000 Server
 * A basic understanding of WMI, XML, and VBScript

back to the top

How to Generate an XML Representation of Your WMI Objects
  Start any text editor, such as Microsoft Notepad, and then cut and paste the following code into a new text file: 'to create an SWbemNamedValueSet object set context = CreateObject(&quot;wbemscripting.SWbemNamedValueSet&quot;)

'initialize the object to set the context context.add &quot;PathLevel&quot;, 2 context.add &quot;IncludeQualifiers&quot;, false context.add &quot;ExcludeSystemProperties&quot;, true

'retrieve the object/class to be represented in XML. set myObj = GetObject(&quot;winmgmts:\\.\root\cimv2:win32_LogicalDisk&quot;)

'Invoke the GetText_ method of the instance created in the preceding 'step, using 1 as the parameter to specify the DTD that corresponds 'to CIM DTD version 2.0, or 2 to specify the DTD that corresponds 'to WMI DTD version 2.0. strText = myObj.GetText_(2,,context)

'Validate that the XML generated in Step 3 is well-formed XML by 'creating and initializing an XML Document Object Model (DOM) object 'and load the XML text into it. set xml = CreateObject(&quot;Microsoft.xmldom&quot;)

'initialize the xmldom object so results are returned synchronously xml.async = false

'load the XML into the xmldom object xml.loadxml strText

'Save the XML Document. xml.save &quot;c:\wmidata.xml&quot; An SWbemNamedValueSet object is a collection of SWbemNamedValue elements. These items are added to the collection by using the SWbemNamedValueSet.Add method. They are removed by using the SWbemNamedValueSet.Remove method and retrieved by using the SWbemNamedValueSet.Item method. You can access these methods to fill in any context information that is required by a dynamic provider. After you call one of the SWbemServices methods, you can reuse the SWbemNamedValueSet object for another call.

NOTE: After you complete step 1, you create a file that is called &quot;Wmidata.xml&quot; that will be saved in drive C. If you want to save this file in another location, modify the path that is passed to the Save method in the last step in the script.

 Save this file and name it &quot;Wmidata.vbs&quot;. Double-click Wmidata.vbs to run the script

back to the top

Keywords: kbhowto kbhowtomaster KB309680

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.