To read a Microsoft System Center Configuration Manager 2007 object instance by using the managed SMS Provider, use WqlConnectionManager.GetInstance. The GetInstance method takes a string that identifies a specific object instance and returns an Microsoft.ConfigurationManagement.ManagementProvider.IResultObject object that is used to access the object.

The following example function shows the name and description for a supplied package identifier.

To read a Configuration Manager object

  1. Set up a connection to the SMS Provider. For more information, see How to Connect to an SMS Provider in Configuration Manager by Using Managed Code.

  2. Call WqlConnectionManager class GetInstance method to get the IResultObject object for the object you want.

  3. Display the properties of the IResultObject.

Example

The following code example shows how to read a Configuration Manager object.

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

  Copy Code
public void DisplayPackageName(WqlConnectionManager connection, string packageID)
{
	try 
	{
		// Get the package.
		IResultObject package = connection.GetInstance(@"SMS_Package.PackageID='" + packageID + "'");
		Console.WriteLine("Package Name: " + package["Name"].StringValue);
		Console.WriteLine("Package Description: " + package["Description"].StringValue);
}
	catch (SmsException ex)
	{
		Console.WriteLine("Failed to get 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.

PackageID

  • Managed: String

A valid package identifier. Obtained from the SMS_Package class PackageID property.

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.