It has been long time since I posted part 1 in the registry hacks series, and I hope you read it 10 times like you were suppose to. After much thought I’ve decided that I’ll continue the posts on registry hacks by talking about the Classes Root. Now, for those of you who forgot what the Classes Root is, go and read part 1. If you decide not to, though, (hey, it’s your computer’s funeral, not mine) here is a quick reminder: the Classes Root is the “drive” in the registry that contains information about how to handle files types such as what name, what context menu to show, what icon to show, what to do when double clicking it, etc.
When you open up the Classes Root you’ll see a huge list of extensions starting with *:
If you scroll down a bit further, you’ll notice that soon the list of extensions end – after the extensions starting with .z – and the registry keys are no longer extensions, but rather they are the definitions for the extensions:
To make it easier to work with multiple different extensions that are really the same file type, like JPG and JPEG, Microsoft set it up so that you can create a definition and then link it to each different extensions. To put it in an analogy, the extension is the house address while the definition is the actual house. Keep in mind the difference between extensions and definitions and the relationship between them because that is really important.
Clicking on any of the extensions will reveal some values:
The only two we care about is (Default) and Content Type: (Default) is the name of the definition for that extension, while Content Type is the MIME type that web developers are probably familiar. Only the (Default) value is required for a key, though if the file does have a MIME, it’s not a bad idea for it to have Content Type also.
For every name present in the (Default) value for an extension, there is a corresponding definition key. For example, for the .png extension shown in the screenshot above, there is a pngfile definition:
This definition controls some key aspects for the file extension it is connected to, such as what the file type is called, the icon used by default, and what items appear in the right-click context menu for that file type. In this case, for definitions, (Default) is the name of the file type, like PNG Image (see above screenshot), Microsoft Word Document, or Video File. It can be any string, and yes spaces are allowed.
Under the definition key, there are a few sub keys:
The two we are interested in are DefaultIcon and shell:
- DefaultIcon is exactly what it sounds like – controls what is the icon that will appear by default for the file extension the definition is connected to. The (Default) value is the location of the icon to show in Windows for that file type:
For this (Default) value, you are allowed to either point it to the location of an icon file (i.e. C:\Icons\icon.ico) or the location of an icon embedded in an executable or a DLL (i.e. C:\Windows\System32\url.dll,0).
- Shell contains a list of the items that appear in the right-click context menu for the associated file extension:
Not all the items you see when you click on a file are here; this list only contains items added specifically for this file type (as opposed to be global), like Open or Print. For each item there is a sub key with an internal name of the item, as you can see from the screenshot above. Each key’s (Default) value is the text shown to the user in the right-click context menu:
The name of the registry key and the (Default) value may be, and probably are, the same, except the key cannot have any spaces; they can be different too, though.
Under each item’s key there is another key called command:
(Default) for command is the command that is run when the item is clicked on (usually double left-click, but will vary depending on your computer settings). For example, as you can see in the above screenshot, clicking on Edit for a Word Document opens Microsoft Word: “C:\Program Files\Microsoft Office\Office12\WINWORD.EXE” /n /dde. The /n and /dde can be considered command line parameters – they give Windows special instructions on how to execute the command in question. Often times you may also find a %1 at the end of the command string. When you click on a menu item, Windows looks at the command, and replaces the %1 in the command string with the file, so if you are opening C:\text.txt and the command is C:\MyProgram.exe “%1”, Windows launches C:\MyProgram.exe “C:\text.txt”.
That is really all I have to say about the Classes Root for now. Keep in mind this is only a basic view of the Classes Root (yes, I know you advanced techies out there must be thinking – “he skipped over so many things”) but for our purposes it is good enough. Get to know the Classes Root well and next time I’ll show off some really cool stuff.
A quick thank you to PC Magazine’s Neil J. Rubenking for showing me this – thanks Neil!