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



The information in this article applies to:

  • Microsoft Windows 2000 Server

This article was previously published under Q309680

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

  1. 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("wbemscripting.SWbemNamedValueSet")
    
    'initialize the object to set the context
    context.add "PathLevel", 2 
    context.add "IncludeQualifiers", false 
    context.add "ExcludeSystemProperties", true 
    
    'retrieve the object/class to be represented in XML. 
    set myObj = GetObject("winmgmts:\\.\root\cimv2:win32_LogicalDisk")
    
    '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("Microsoft.xmldom")
    
    '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 "c:\wmidata.xml"
    					
    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 "Wmidata.xml" 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.

  2. Save this file and name it "Wmidata.vbs".
  3. Double-click Wmidata.vbs to run the script
back to the top

Modification Type:MajorLast Reviewed:9/30/2003
Keywords:kbhowto kbHOWTOmaster KB309680 kbAudITPro