November 27, 2007

MMC Snapin creation

MMC Snapin Creation

There are 2 main versions of MMC available on Windows, MMC 2.0 (Windows 2000 and XP) and MMC 3.0 (Windows Server 2003). I'll mainly explain how to develop a Snap-in with MMC 3.0.

You can upgrade MMC 2.0 to MMC 3.0 using this install supplied by Microsoft

MMC 2.0 snapin:
Download the Platform SDK, Windows® Server 2003 R2 Platform SDK Web Install, from http://www.microsoft.com/downloads/details.aspx?FamilyID=0baf2b35-c656-4969-ace8-e4c0c0716adb&DisplayLang=en

Build an example from the Platform SDK install:
C:\Program Files\Microsoft Platform SDK\Samples\SysMgmt\MMC\mmc2.0\simple>nmake

MMC 3.0 snapin:

How to Develop and MMC 3.0 Snap-in (msdn)

How to create a Snap-in using MMC 3.0 (msdn)

MMC Snap-ins for MMC 3.0 can be developed with the Windows SDK, for information on the snapin classes see msdn Management Console
There is also an opensource .NET library at http://sourceforge.net/projects/mmclibrary

The MMC 3.0 application installation is at http://www.microsoft.com/downloads/details.aspx?FamilyID=61fc1c66-06f2-463c-82a2-cf20902ffae0&DisplayLang=en

Here's an example of how to build a simple Snapin

To develop MMC 3.0 snapins you'll need the microsoft.managementconsole.dll library. This library can be gotten by installing the MMC 3.0, found at http://www.microsoft.com/downloads/details.aspx?FamilyID=61fc1c66-06f2-463c-82a2-cf20902ffae0&DisplayLang=en
Add this library as a reference to your Snapin project and you'll have access to it's functionality.
.

You can also install the Windows Server 2003 R2 Service pack. Some example code is available on the web.

You Snapin is a Class Library project. It's main Class should implement the Microsoft.ManagementConsole.SnapInInstaller interface and override these 3 methods

public override void Install(IDictionary stateSaver);
public override void Rollback(IDictionary savedState);
public override void Uninstall(IDictionary savedState);

MMC 3.0 - A managed code 'task manager' MMC 3.0 snap-in

Installation
The procedure to install the MMC Snapin in MMC 2.0 and MMC 3.0 is different, see below for further details:

MMC 2.0 snapin:


Register the snapin with MMC:
C:\Program Files\Microsoft Platform SDK\Samples\SysMgmt\MMC\mmc2.0\simple\WIN2000_DEBUG>regsvr32 Simple.dll

MMC 3.0 Snapin
This snapin was build with MMC 3.0 as ManagementConsoleSnapin.dll

The resultant DLL, C:\MySnapinProject\bin\Debug\ManagementConsoleSnapin.dll, can be installed as a snapin to MMC 3.0 as follows: >C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\installutil.exe C:\MySnapinProject\bin\Debug\ManagementConsoleSnapin.dll

and uninstalled using:
>C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\installutil.exe /u
C:\MySnapinProject\bin\Debug\ManagementConsoleSnapin.dll

After installation the snapin appears in the MMC Snapin list as "My Management Console". Add the snapin to MMC and select OK. The Snapin is now ready for use.

MMC Snapin Debugging
The easiest way to debug the MMC while installing the Snapin is to set the Project Properties of your snapin project, in the project properties Debug tab select 'Start External Program' and enter 'C:\WINDOWS\system32\mmc.exe' in the field. Now when you hit F5 the MMC app will launch, you now 'Add\Remove Snapin' from the MMC's File menu.


2 comments:

Valeriano said...

Hi!

I'm trying to install a MMC with a Setup Project ... but I can't get it.

With InstallUtil.exe runs fine, but with a Setup Project does't appear in the snap-in list of mmc.exe.

What is the good way to do it?

Thanks in advance.

Kind regards.

learnerplates said...

Veleriano,
Welcome, I hope some of my posts are of use to you.

I'll presume we're talking about MMC 3.0.

How are calling the MMC installation from your Setup Project? Have you just added it as a project output? Or maybe a Custom Task?

Have you MMC 3.0 installed on the a machine that you are running the installer (If not and you have mmc 2.0 you'll not see your snapin in the list).

LP.