The Case for an MMC SnapIn

We'll work on a MMC snap-in example in this chapter because I consider it the most common example of a specialty application. A lot of developers on Microsoft's various newsgroups have asked how to create an MMC snap-in, and I'm sure that many more are wondering how to perform this task. The lack of any MMC projects in Visual Studio .NET and the changes to the MMC snap-in in Windows XP have led some developers to believe the MMC snap-in is going to become history very soon. That may be, but for today, the MMC snap-in still represents the best way of writing a configuration utility.

MMC is the application used by Windows 2000 and Windows XP to manage operating system functionality. You'll find it in the \System32 folder as MMC.EXE. MMC is a container application that hosts snap-ins—the container doesn't do much more than provide a place for the snap-in to perform its work. Of course, the container does lend a consistency to the user interface and ensures that each snap-in behaves in a certain way. Each configuration of snap-ins is called a console, and you'll find a list of these consoles in the Administrative Tools folder of the Control Panel. Figure 12.2 shows a typical example of a console—the Performance console.

In this case, the System Monitor and the Performance Logs and Alerts are actually two separate MMC snap-ins that appear together in this console. You can use the File 0 Add/Remove Snap-in command to display the Add/Remove Snap-in dialog box, which contains a list of snap-ins used to create a particular console, as shown in Figure 12.3. Note that the folders beneath the Performance Logs and Alerts entry in Figure 12.2 are actually part of a single MMC snap-in.

igure 12.2: MMC consoles pair one or more MMC snap-ins with the MMC container application.

You should also notice that the System Monitor is an ActiveX Control snap-in, not a standard MMC snap-in. You can always use standard ActiveX controls as MMC snap-ins, but most ActiveX controls lack the interfaces required to interact with the MMC container application. For example, I created a special type of pushbutton and inserted it in MMC (just to see what it would do). Yes, I could see the button and it reacted when I clicked it, but that's it. However, my pushbutton example does demonstrate that MMC is just another way to use COM, nothing more or less.

Notice the Extensions tab in Figure 12.3. Some MMC snap-ins include augmented features—additions that you can choose to include in the console. Figure 12.4 shows the extensions for the Computer Management snap-in. The extensions in this list add data views to a console created using the Computer Management snap-in. If you scroll through the list, you'll notice that some snap-ins are also used in stand-alone mode, which indicates the duality of their nature. Extension snap-ins rely on the host snap-in for some types of services and must implement additional interfaces as well as provide extra code for working with the host snap-in. However, they also provide the basic level of snap-in functionality that we'll discus in the first example in the chapter.

igure 12.3: Many consoles appear to contain just one control but are actually made of several controls.

igure 12.4: Some snap-ins provide extended functionality for a stand-alone MMC snap-in.

The "magic" for the MMC application is the MSC file. This file contains the information required to create a console. In fact, if you look in the \System32 folder, you'll find the PerfMon.MSC file that contains the information to create the Performance console. Interestingly enough, this file uses XML to store information and has used it long before XML was very popular on the Internet. Figure 12.5 shows a view of the MSC file using XML Notepad.

Tip XML is almost, but not quite, readable by the average human. Reading simple files is almost a trivial exercise, but once the data gets nested a few layers deep, reading it can become tiresome. That's why you should have a tool for reading XML in your developer toolkit. The only problem is that some of these tools cost quite a bit for the occasional user. Microsoft has remedied this problem a little with the introduction of XML Notepad

(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnxml/_html/xmlpaddownload.asp). This utility is free for the price of a download and does a reasonable job of reading most XML files.

« Ul r«di N*

D *U *«a * PS

♦ -P13I #

smtvi

»«•¡a

a

• _J r

. _| «M

► jr*«iM

- iTr/Tvi

• a ib

»W. K* lOl 00*1

LI

♦ a sb

■cMttsemii

♦ ««HMtWM

LJSM*M

« a SB

1 : V: C'l *

- -J«**«

>«r imll

Figure 12.5: MMC relies on MSC files that store configuration information in XML format.

Figure 12.5: MMC relies on MSC files that store configuration information in XML format.

Figure 12.5 shows an important bit of information about the MMC application. The first and third MMC snap-in globally unique identifier (GUID) entries correspond to the MMC snap-ins for the console. (You can validate this information by looking the GUIDs up in the registry using RegEdit.) The third entry actually points to the control responsible for handling ActiveX controls. If you look up the GUID for the second GUID entry, you'll notice that it's for a folder snap-in, the Console Root folder in Figure 12.2.

MMC does have quite a bit to offer in the way of control organization and presentation. While this chapter won't explore every MMC feature, you'll learn about quite a few of them. We'll explore the MMC application in more detail later as part of the example. For now, you have enough information to understand some MMC basics.

Was this article helpful?

0 0

Post a comment