5/13/2011

The code example in this topic demonstrates how to call the code examples that are included in some WMI methods in the WMI Provider Referencesection.

In this example, replace SNIPPETMETHODNAMEwith the specific WMI method example name that you want to run.

Note:
In some cases, you will have to make changes, such as adding parameters, to make the code work.

For more information about using the code examples for remote Windows Management Instrumentation (WMI) connections, see Connecting to WMI on a Remote Computer on MSDN.

Example

Copy Code
using System;
using System.Collections.Generic;
using System.Text;
using System.Management;
using System.Management.Instrumentation;

namespace EmbeddedDeviceManagerSnippets
{
	class Program
	{
		static void Main(string[] args)
		{
			SnippetClass snippets = new SnippetClass();

			// Make connection to provider.
			ManagementScope scope = snippets.Connect();

			// Call snippet method and pass the provider connection
object.
			snippets.SNIPPETMETHODNAME(scope);
	}
}

	class SnippetClass
	{
		public void SNIPPETMETHODNAME(ManagementScope scope)
		{
			// Insert code example here.
	}

		public ManagementScope Connect()
		{
			ConnectionOptions options = new ConnectionOptions();
			options.Impersonation = ImpersonationLevel.Impersonate;
			options.Authentication =
System.Management.AuthenticationLevel.Default;
			options.EnablePrivileges = true;
			ManagementScope connectScope = new
System.Management.ManagementScope();
			connectScope.Path = new ManagementPath("root\\EDM");

			connectScope.Options = options; 	
			try
			{
				connectScope.Connect();
		}
			catch
			{
				Console.WriteLine("Connection Failed...");
		}

			return connectScope;
	}
}
}

Compiling the Code

Namespaces

System

System.Collections.Generic

System.Text

System.Management

System.Management.Instrumentation

See Also