Creating a Sibling Namespace with MOF Code

Another way of creating a namespace is to use Managed Object Format (MOF) code to create a sibling namespace. A sibling namespace is a namespace that does not exist as a child of the current namespace.

The following procedure describes how to create a sibling namespace with MOF code.

Aa389757.wedge(en-us,VS.85).gifTo create a sibling namespace with MOF code

  1. Insert the #pragma namespace command into your MOF code prior to the namespace declaration.

    The #pragma namespace command instructs WMI where to create the instances following the directive.

  2. Create an instance of the __Namespace class.
  3. Compile your code with the mofcomp utility or the IMofCompiler interface.

    For more information, see Compiling MOF Files.

The following MOF code example describes how to create a namespace as a sibling to the "Root\CIMv2" namespace.

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

instance of __Namespace 
    Name = "MyNamespace";