How To Enumerate Windows Management Instrumentation Namespaces (246204)



The information in this article applies to:

  • Microsoft Windows Management Instrumentation 1.0
  • Microsoft Windows Management Instrumentation 1.1
  • Microsoft Windows Management Instrumentation 1.5

This article was previously published under Q246204

SUMMARY

You cannot enumerate all the Windows Management Instrumentation (WMI) namespaces on a computer by using a single query in a single namespace.

MORE INFORMATION

In order to enumerate all the namespaces, you must first connect to the "root" namespace, query for all the "__NAMESPACE" instances, and for each instance recursively repeat this process.

The following Microsoft Visual Basic code snippet is a recursive subroutine that enumerates the namespaces under the namespace tree rooted at the namespace specified in the parameter.
Sub PrintNamespaces(namespace As String)

Debug.Print namespace
Set locator = CreateObject("WbemScripting.SWbemLocator")
Set wmi = locator.ConnectServer(".", namespace)
For Each obj In wmi.InstancesOf("__NAMESPACE")
    PrintNamespaces namespace + "\" + obj.Name
Next

End Sub

To enumerate all of the namespaces on the computer, call the subroutine with "root" as the parameter:
PrintNamespaces "root"
				

Modification Type:MinorLast Reviewed:10/6/2004
Keywords:kbhowto KB246204 kbAudDeveloper