Using Visual Studio .NET Management Extensions and the WEPOS WMI Management Classes

2/27/2008

A Visual Studio extension called Management (WMI) Extensions for Visual Studio .NET 2003 Server Explorer adds management services to the Server Explorer in Visual Studio .NET. Using this extension, you can navigate the Microsoft.PointOfService namespace and drag the instances of the classes onto your project’s Class Designer.

This feature requires Microsoft Visual Studio .NET 2003 and the Windows Embedded for Point of Service (WEPOS) runtimes to be installed on the local development computer. You can learn more about Management Extensions for Visual Studio at this Microsoft Web.

To use the extension

  1. Launch Visual Studio .NET 2003 and open the Server Explorer window.

  2. Expand the Servers node, and then expand the Machine node.

  3. Right-click the Management Classes node and then click Add Classes on the shortcut menu.

  4. In the Add Classes dialog box, expand the root\MicrosoftPointOfService node in the Available Classes tree view.

  5. Select the DeviceProperty class, and then click Add to add the class to the Server Explorer. Repeat this step for the LogicalDevice, PosDevice, and ServiceObject classes.

To use the management classes

  1. Create a .NET project.

  2. Open the Server Explorer.

  3. Right-click the DeviceProperty node, and then click Generate Managed Class on the shortcut menu to add the generated class to the project. Repeat this step for the LogicalDevice, PosDevice, and ServiceObject classes to generate managed classes.

To use an instance of a management class

  1. In the Server Explorer, expand the desired class to list the available class objects.

  2. Drag the instances onto the projects class designer.

Example

The following code example demonstrates the use of the PosDevice class GetInstances method to enumerate Point of Service devices. It creates a collection of the devices within a scope. It then lists the type, name and path for each device in the collection and indicates whether the device is enabled or disabled.

using System;
using System.Management;
using ROOT.MICROSOFTPOINTOFSERVICE;

namespace Management
{
   public class Test
   {
      public Test()
      {
         ManagementScope scope = new ManagementScope("root\\microsoftpointofservice");
         scope.Connect();
         PosDevice.PosDeviceCollection devices = PosDevice.GetInstances(scope, "");
         string format = "{0,10}\t{1,25}\t{2}\t{3,50}";
         if( devices.Count > 0 )
            Console.WriteLine(format, "Type", "Name", "Enabled", "Path");
         foreach( PosDevice d in devices )
         {
            Console.WriteLine(format, d.Type, d.SoName, d.Enabled ? 'Y' : 'N', d.Path); 
         }
      }

      static int Main()
      {
         Test t = new Test();
         return 0;
      }
   }
}

An alternative to using the GUI to create your wrapper is to use the command-line tool called mgmtClassGen.exe. This tool will generate a .NET class wrapper for classes in a WMI namespace. This feature requires Microsoft Visual Studio .NET 2003 and the Microsoft WEPOS runtimes to be installed on the local development machine. The tool is found in the \Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin folder.

Using this tool, you can create a .NET class for the WMI root/microsoftpointofservice/PosDevice class as follows:

mgmtClassGen.exe /n root/microsoftpointofservice /l cs PosDevice

This command creates the C# class in a file called PosDevice.cs in the current directory. Create a C# command-line project and add the PosDevice.cs file to the project. Compile the following C# code against it. This code simply enumerates the PosDevice classes on the local computer.

Note

Before you run this sample on Windows XP Professional or Windows Embedded for Point of Service, you must install the .NET Framework v1.1 SP1

See Also

Reference

PosCommon

Other Resources

POS Device Manager
Using the POS Device Manager Command-Line Tool
Using the WMI API to Manage Devices