To read a Configuration Manager client Windows Management Instrumentation (WMI) object, in System Center 2012 R2 Configuration Manager, you use a ManagementObject object to read the WMI object.

To read a WMI object

  1. Set up a connection to the Configuration Manager client WMI namespace. For more information, see How to Connect to the Configuration Manager Client WMI Namespace by Using System.Management.

  2. Create a ManagementObject object.

  3. Create a ManagementPath object with the ManagementScope path you obtain from step one.

  4. Assign the ManagementPath object to the ManagementObject path property.

  5. Call the ManagementObject object Get method to get the object from the WMI provider.

  6. Use the ManagementObject object to read the WMI provider object properties.

Example

The following C# code example gets the Configuration Manager client WMI object SMS_Client object and displays its properties.

For information about calling the sample code, see How to Call a WMI Class Method by Using System.Management.

C#  Copy Code
void ReadObject(ManagementScope scope)
{
	try  // Gets an instance of a CCM_InstalledComponent.
	{
		// Get the object.
		ManagementObject obj = new ManagementObject();
		ManagementPath path = new ManagementPath(scope.Path + ":CCM_InstalledComponent.Name='SMSClient'");

		obj.Path = path;
		obj.Get();

		// Display a single property.
		Console.WriteLine(obj["DisplayName"].ToString());

		// Display all properties.
		foreach (PropertyData property in obj.Properties)
		{
			Console.WriteLine(property.Name + " " + property.Value);
	}
}
	catch (ManagementException e)
	{
		Console.WriteLine("Failed to get component: " + e.Message);
		throw;
}
}

This example method has the following parameters:

Parameter Type Description

scope

  • ManagementScope

The client management scope. The namespace should be root\ccm.

Compiling the Code

Namespaces

System

System.Management

Assembly

System.Management

Robust Programming

The exception that can be raised is System.Management.ManagementException.

See Also