Creating a Namespace

[This is preliminary documentation and subject to change.]

Namespaces are used in WBEM to differentiate among the groups of classes and instances that represent particular management environments. Each new schema or version of a schema requires a new namespace. For example, all of the classes and instances that are defined in the Microsoft® Win32® schema reside in the \\root\cimv2 namespace.

Namespaces are represented by the __Namespace system class and classes that derive from this system class. The __Namespace class has a single property called Name, which must be unique within the scope of the parent namespace. The Name property must be set to a string that begins with a letter. All other characters in the string can be letters, digits, or underscores. All characters are case-insensitive.

Namespaces can be created using the Managed Object Format (MOF) language or the CIMOM API.

To create a new namespace with MOF, create a file with an instance of the __Namespace system class as follows:

instance of __Namespace 
{
    Name = "MyNamespace";
};
 

This example shows the creation of a new namespace within the current namespace.

To create a namespace within a specific namespace other than the current one, use the #pragma namespace directive prior to the instance declaration. The next example shows how to create a namespace as a sibling to the \Root\Default namespace:

#pragma namespace("\\\\.\\Root")

instance of __Namespace 
{
    Name = "MyNamespace";
};
 

To create a namespace using the COM interfaces of the CIMOM API:

  1. Call IWbemClassObject::SpawnInstance to define an instance of the __Namespace system class.
  2. Call IWbemServices::PutInstance, setting the contents of the pInst parameter to the new instance.