Udostępnij za pośrednictwem


Mshsnapin (part 2): developing a mshsnapin.

To develop a mshsnapin, you can use following three simple steps,

  1. Create a class derived from MshSnapIn class.
  2. Build an assembly to contain the mshsnapin class created in step1 and also other cmdlet/provider classes to be included in the mshsnapin.
  3. Install the mshsnapin assembly created in step2 using installutil.exe.

Following is the sample code for a mshsnapin class. Basically, you just need to fill in information about name, vendor and description of the mshsnapin.

namespace XYZ.TestNameSpace
{
[RunInstaller(true)]
public class MyMshSnapIn : MshSnapIn
{
public MyMshSnapIn()
: base()
{
}

        /// <summary>
/// Gets name of the mshsnapin. This will be the string to be used for registering this
/// mshsnapin.
/// </summary>
public override string Name
{
get
{
return "XYZ.TestNameSpace.MyMshSnapIn";
}
}

        /// <summary>
/// Gets vendor of the mshsnapin.
/// </summary>
public override string Vendor
{
get
{
return "XYZ Corporation";
}
}

/// <summary>
/// Gets description of the mshsnapin.
/// </summary>
public override string Description
{
get
{
return "This is a test mshsnapin";
}
}

}

For step 2, you build the mshsnapin code (from step 1), cmdlet code, and provider code (from your normal cmdlet and provider development) into one assembly (for example MyMshSnapin.dll).

For step 3, you install the snapin assembly by running following command. (installutil.exe is an standard utility from CLR).

installutil.exe -i MyMshSnapin.dll

- George