To create a Configuration Manager 2007 object by using the managed SMS Provider, use WqlConnectionManager.CreateInstance method. The CreateInstance method takes the required object type as a string parameter and returns an Microsoft.ConfigurationManagement.ManagementProvider.IResultObject object that is used to populate the new object. The IResultObject.Put method must be called to submit the object to the SMS Provider.

To create a Configuration Manager object

  1. Set up a connection to the SMS Provider. For more information, see About the SMS Provider in Configuration Manager.

  2. Using the WqlConnectionManager connection object you obtain in step one, call CreateInstance to create the required the WMI object, and receive its IResultObject object instance.

  3. Populate the IResultObject properties.

  4. Commit the IResultObject to the SMS Provider.

Example

The following example demonstrates how to create and then populate a new Configuration Manager package (SMS_Package).

For information about calling the sample code, see Calling Configuration Manager Code Snippets.

  Copy Code
public void CreatePackage(WqlConnectionManager connection)
{
	try
	{
		IResultObject package = connection.CreateInstance("SMS_Package");
		package["Name"].StringValue = "Test Package";
		package["Description"].StringValue = "A test package";
		package["PkgSourcePath"].StringValue = @"c:\Package Source";

		package.Put();
}

	catch (SmsException ex)
	{
		Console.WriteLine("Failed to create package. Error: " + ex.Message);
		throw;
}
}

This example method has the following parameters:

Parameter Type Description

connection

Managed: WqlConnectionManager

A valid connection to the SMS Provider.

Compiling the Code

Namespaces

System

System.Collections.Generic

System.ComponentModel

Microsoft.ConfigurationManagement.ManagementProvider

Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine

Assembly

microsoft.configurationmanagement.managementprovider

adminui.wqlqueryengine

Robust Programming

See Also


Send comments about this topic to Microsoft.