用C# 创建 MMC Snapin

本文档详细介绍了如何利用C#编程语言创建一个MMC(Microsoft Management Console)Snap-in,涵盖了从构造函数到组件和控件如ListView的使用,深入探讨了属性设置和Windows管理集成。
摘要由CSDN通过智能技术生成

绪论

The article/code snippet helps in creation of MMC Snapin using C#.

背景

The framework for building management consoles for Windows NT/2000 is developed by Jim. Jim is the author for ironringsoftware.com. In our article we will be using this framework to derive the UI for the management console. Detailed step for generating the snapin console is explained below.

代码使用步骤

Here are the steps to use the MMC library created by the author at ironringsoftware.com to create management consoles for Windows NT/2000

Step 1: 下载框架

You need to download the latest source of MMC Snapin Framework from ironringsoftware.com .

The zip file downloaded contains three projects.

  • First is <MMCFormsShim> which is the implementation of the framework in C++.
  • Second is <MCLib> which mainly is the Runtime Callable Wrapper (RCW) for the underlying C++ code and also contains the implementation for the Snapin objects like nodes, menus etc., with features like event handlers etc. defined.
  • Finally <MCTest> is the project which shows the usage of the framework to generate MMC Snapin.

Step 2: 查看示例

  • Set <MMCTest> project as the startup project.
  • When executed the project, it displays Microsoft Management Console.
  • Click on menu Console -> Add/Remove Snap-in..
  • Click Add button
  • Select "MMC Library Test Snapin" and click Add button and then the Close button
  • Finally you shall be viewing the Snapin sample in your Console.

Step 3: 初始化

  • Create a directory "C:/FileActDemo" with few sample files and sub directories in it
  • View the properties of project <MMCTest>. Set the value for "Working Directory" property under "Configuration Properties -> Debugging" section appropriately.
  • Open <dlldatax.c> file in project <MMCFormsShim> and replace the value for "#define _WIN32_WINNT" from "0x0400" to the appropriate value. for e.g. "0x0586"

Step 4:如何创建新接点

例1:Let us take an example of creating a node which contains all the directory information on the left pane and the file information in the result pane.

  • Open <BaseNode.cs> file in project <MMCLib> and add a new protected class variable as shown in the code below
//This is the variable which holds the data passed from the framework.
protected Hashtable m_Properties;    
  • Initialize the variable in the constructor of the class as shown in the code below
m_Properties = new Hashtable();    
  • This is the public property used to pass the values from the framework to the form. Add public property for the class to access the protected variable just defined as shown in the code below
public Hashtable Properties {
  get { return m_Properties; }
  set { m_Properties = value; }
}    
  • Add new .cs file into project <MMCLib> and name it as <DirectoryNode.cs>. Replace the code of the class file with the code below
// 
//Code block for DirectoryNode.cs
//
using System;
using System.IO;
using System.Data;
using System.Runtime.InteropServices;

namespace Ironring.Management.MMC {
  /// <summary>
  /// Any node which we create should be derived from the BaseNode.
  /// This node will get displayed in the left pane of the MMC. 
  /// 
  /// </summary>
  public class DirectoryNode : BaseNode {
    protected DataTable m_table = null;

    public DirectoryNode(SnapinBase snapin) : base(snapin) {
    }

    /// <summary>
    /// This is the public property to get/set the datatable value.
    /// This datatable values are the ones which gets displayed in the right pane
    /// of the MMC for the respective node item selected in the left pane.
    /// </summary>
    public DataTable Table {
      get { return m_table; }
      set { m_table = value; }
    }

    /// <summary>
    /// This method is called by the MMC snap to populate the data for listview 
    /// in the right pane, for the respective node item selected in the left pane.
    /// </summary>
    public override void OnShow() {
      IConsole2 console = Snapin.ResultViewConsole;

      IHeaderCtrl2 header = console as IHeaderCtrl2;
      OnShowHeader(header);

      IResultData rdata = console as IResultData;
      OnShowData(rdata);

      rdata.SetViewMode((int)ViewMode.Report);
    }

    /// <summary>
    /// This method is called by the OnShow() method to 
    /// display header for the listview 
    /// in the right pane, for the respective node item selected in the left pane.
    /// </summary>
    public virtual void OnShowHeader(IHeaderCtrl2 header) {
      try {
        if (Table != null) {

          foreach (DataColumn col in Table.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值