Home > database >  Registry - Having problems understanding how Windows determines which application will open a certai
Registry - Having problems understanding how Windows determines which application will open a certai

Time:06-08

I'm trying to develop a utility allowing users to register custom file extensions, including custom icons and open commands. Yeah, I know, there's a thousand utilities doing exactly that out there, but I'm mainly doing it for fun and to get a better understanding of the Windows file system.

I know that the process involves having a registry key either in HKCR/.whatever, HKLM/Software/Classes/.whatever, or HKCU/Software/Classes/.whatever. Regardless of where it is, this key contains a reference to a different key under the same group. This key then usually contains two subkeys: DefaultIcon, containing the path to the icon file (or to a binary file, plus an icon index), and shell, which contains open and then command. Inside of this one is the command used to open a file with that extension.

However, it's apparently not this easy. I've noticed that XML files, at least on my system, point to the xmlfile key, which contains a DefaultIcon subkey pointing to "%1". Clearly an indicator that the icon used should be that of the program that opens it. I'm fine with it. However, once I check in shell/open/command, I find that Windows apparently tries to open XML files with... some obscure Office program (MSOXMLED.EXE)?

This is definitely not what my system opens XML files with. When I double click on one, Notepad opens, and therefore the file system shows the Notepad icon. However, nowhere in the registry did I find a subkey somehow associating XML files with Notepad .

I've seen that the .xml key also contains an OpenWithList subkey, but this one only contains Illustrator.exe (and no, I don't open XML files with Illustrator). I also found OpenWithProgids, but that one only hints to Visual Studio (and again, that's not what I use).

What am I missing? Is there some other mechanism I'm unaware of?

CodePudding user response:

In Windows 95 you would register you extension (.foo for example) under HKCR\.foo and the default value there points to the ProgId. This might be HKCR\FooFile for example. This is where the DefaultIcon and the verbs are stored. The default verb is read from the default value under HKCR\FooFile\shell. If there is no value there then open is used as the verb (HKCR\FooFile\shell\open\....

This is still how you register a custom extension today. However, at some point (Windows 7?) the way Windows determines the extension to ProgId mapping changed. If the user uses "Open with" or the control panel default applications feature Windows will write a ProgId override in the undocumented FileExts Explorer key. In Windows 8? an additional UserChoice value was added that stores a encrypted value based on the extension and ProgId so that 3rd-party applications could not edit the registry to make themselves the default. Firefox knows how to encrypt this value to make themselves default...

In your specific case you probably told "Open with" to always open .xml files with Notepad and the FileExts mapping might point to HKEY_CURRENT_USER\Software\Classes\Applications\npp.exe or something similar.

  • Related