To connect to the Configuration Manager client Windows Management Instrumentation (WMI) provider, you create a ManagementScope object in the \\Client\root\ccm namespace.

You use the ManagementScope object to read and query WMI objects. For example, How to Read a WMI Object by Using System.Management.

To connect to the Configuration Manager client WMI provider

  1. In Visual Studio, create a new Visual C# Console Project.

  2. Add a reference to the System.Management assembly.

  3. In the C# source code, add a reference to the System.Management namespace with the following code.

  4. using System.Management;

  5. Create a new class and add the following connection example code.

Example

The following C# code example creates and returns a ManagementScope object on the root\ccm namespace.

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

C#  Copy Code
public ManagementScope Connect()
{
	try
	{
		return new ManagementScope(@"root\ccm");
}
	catch (System.Management.ManagementException e)
	{
		Console.WriteLine("Failed to connect", e.Message);
		throw;
}
}

This example method has the following parameters:

Parameter Type Description

Connection

WqlConnectionManager

A valid connection to the SMS Provider.

Compiling the Code

Namespaces

System.

System.Management.

Assembly

System.Management.

Robust Programming

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

See Also


Send comments about this topic to Microsoft.