Writing managed control panel items

Fri, December 22, 2006, 09:36 AM under Windows | Vista
In the past, if you had to develop control panel items you would start thinking about .cpl files. With Windows Vista, there seems to be a tendency to take advantage of the new ability to create them in separate executables! Those of you that know me long enough can see where I am going with this... it means that we can develop these in managed code now :-)

I will assume that you have a scenario for actually integrating with the control panel and I will just share the mechanics. Create your managed Windows Forms application and give it whatever UI you want. You actually don’t have to do anything special in the project. In fact, you could even reuse your existing main application and just use a command line option for when it gets launched from the control panel.

So once you have the exe, how do you integrate it with the control panel? The answer is by adding some registry entries.
1. Buy yourself a GUID. In all my screenshots below, replace my guid ({ABB4AAE7-3D21-45f7-AA1C-F470FAB07B89}) for the one you have.

2. Create a key with this GUID under HKLM at the path shown in the screenshot below (hint: look at the statusbar):

3. Do the same this time under HKCR at the path shown in the screenshot below:

4. Look at the values for the screenshot above. For the first 3 values you can enter anything you like. The last value points to a path and do not worry about that right now. The 4th value (System.ControlPanel.Category) tells the system under which category you want a link to your executable to appear in. I’ve chosen 7 and 9 which are the “User Accounts” and “Ease of Access” categories. The following screenshot shows the effect of the few registry entries we created. Note how values from above match the UI (inc. tooltip).

You can find your link under both aforementioned categories and it is immediately searchable as well.

5. If you click on your item, explorer.exe will show an error box “Application not found”. Close the control panel and let’s go make one more registry entry. Create 3 subkeys as shown in the following screenshot and note how the default value under Command specifies the path to the executable (you could have specified a command line argument if you wanted):

Launch the control panel again, and this time when clicking on your link, your application will open.

Also, remember the string we entered for the System.ApplicationName registry value? If you entered the same as me, you can now launch your application from the command line
control /name Daniel.MothPanelApplet

6. An optional additional step is to specify task links under your item. This is where the path to the file we mentioned above comes in. At the moment your System.Software.TasksFileUrl value points to an invalid path. Make it point to this file after you copy it to your machine. Close Control Panel and after reopening it, under “User Accounts”, you find a something like the following:

If you navigate to the “Ease of Access” category, you’ll find a slight variation as shown in the screenshot behind this link.

More Info
There is a lot more to check out including how to change the icon that appears in the control panel, what the numbers for the other categories are, how to launch other items from the command line, design guidelines, explanations on the XML file for tasks, creating cpl items, what else is new in Vista and a lot more. The following msdn links should cover that material for you:

Tour of UI

Quick intro similar to mine

UX guidelines for control panels

Comprehensive control panel overview