Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
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 Using System.Management.
To connect to the Configuration Manager client WMI provider
In Visual Studio, create a new Visual C# Console Project.
Add a reference to the System.Management assembly.
In the C# source code, add a reference to the System.Management namespace with the following code.
using System.Management;
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.
public ManagementScope Connect()
{
try
{
return new ManagementScope(@"root\ccm");
}
catch (System.Management.ManagementException e)
{
Console.WriteLine("Failed to connect", e.Message);
throw;
}
}
Compiling the Code
Namespaces
System
System.Management
Assembly
System.Management.dll
Robust Programming
The exception that can be raised is System.Management.ManagementException.
See Also
About Configuration Manager WMI Programming
How to Call a WMI Class Method by Using System.Management
How to Perform an Asynchronous Query by Using System.Management
How to Perform a Synchronous Query by Using System.Management
How to Read a WMI Object by Using System.Management