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

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

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 root\MicrosoftPointOfService namespace and drag and drop the instances of the classes into your project’s class designer.

To download this extension, go to:

https://www.microsoft.com/downloads/details.aspx?FamilyID=62d91a63-1253-4ea6-8599-68fb3ef77de1&DisplayLang=en This feature requires Microsoft Visual Studio .NET 2003 and the Microsoft WEPOS runtimes to be installed on the local development machine.

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 choose Add Classes from the popup menu.
  4. In the Add Classes dialog, expand the root\MicrosoftPointOfService node in the Available Classes tree view.
  5. Select the DeviceProperty class, and then click the Add button 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 on the DeviceProperty node, and then choose Generate Managed Class from the popup 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 and drop the instances onto the projects class designer.

Generating Early-Bound Classes for the WEPOS WMI Management Classes

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 PosDevices on the local machine.

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.

  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;
      }
   }
}

© 2005 Microsoft Corporation. All rights reserved.