Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

How to Read a Configuration Manager Object by Using Managed Code

System Center

Updated: October 28, 2009

Applies To: System Center Configuration Manager 2007, System Center Configuration Manager 2007 R2, System Center Configuration Manager 2007 R3, System Center Configuration Manager 2007 SP1, System Center Configuration Manager 2007 SP2

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 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.


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.

public void DisplayPackageName(WqlConnectionManager connection, string packageID)
        // 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);

This example method has the following parameters:


Parameter Type Description


  • Managed: WqlConnectionManager

  • A valid connection to the SMS Provider.


  • Managed: String

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

Compiling the Code










Robust Programming

The Configuration Manager exceptions that can be raised are SmsConnectionException and SmsQueryException. These can be caught together with SmsException.

See Also

© 2015 Microsoft