Upravit

Sdílet prostřednictvím


Creating a Namespace with the WMI API

Another way of creating a namespace is to use the WMI API to create the namespace programmatically. The advantage to creating a namespace programmatically is that you can create the namespace from within an application. However, using the WMI API is more complex than using Managed Object Format (MOF) code, and you cannot as easily share your namespaces with other developers.

The following procedure describes how to create a namespace using the WMI API.

To create a namespace using the WMI API

  1. Use IWbemServices::GetObject to retrieve a pointer to an IWbemClassObject object that points to the __Namespace system class.

  2. Define an instance of the __Namespace system class with a call to IWbemClassObject::SpawnInstance.

  3. Set the Name property of the __Namespace instance with a call to IWbemClassObject::Put.

  4. Create the namespace with a call to IWbemServices::PutInstance.

    The pInst parameter of PutInstance should point to the new instance.