Search code examples
winapiexplorerwindows-shell

Context menu handler option not appearing in shell context menu


Following the Creating Shortcut Menu Handlers for adding a non-canonical verb to the shortcut menu:

HKEY_CLASSES_ROOT
   .myp-ms
      (Default) = MyProgram.1
   MyProgram.1
      (Default) = My Program Application
      Shell
         (Default) = doit
         doit
            (Default) = &Do It
            command
               (Default) = c:\MyDir\MyProgram.exe /d "%1"

I am trying to add one for my custom .base85 file type:

HKEY_CLASSES_ROOT
   .base85
      (Default) = Base85FileType
   Base85FileType
      (Default) = Base-85 Encoded File
      Shell
         (Default) = decode
         decode
            (Default) = &Decode It
            command
               (Default) = notepad.exe "%1"

Which you can see in my .reg dump:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\.base85]
@="Base85FileType"

[HKEY_CLASSES_ROOT\Base85FileType]
@="Base-85 Encoded File"

[HKEY_CLASSES_ROOT\Base85FileType\shell]
@="decode"

[HKEY_CLASSES_ROOT\Base85FileType\shell\decode]
@="&Decode It"

[HKEY_CLASSES_ROOT\Base85FileType\shell\decode\command]
@="notepad.exe \"%1\""

But no "D͟ecode It" context menu option appears. What am i doing wrong?

Research Effort

Windows does not even recognize the file type description "Base-85 Encoded File", instead showing a default BASE85 File:

enter image description here

I've tried rebooting.

What do you get when you try it?


Solution

  • Your registration is correct but something on the system had already claimed that extension. This is stored in the undocumented Explorer FileExts key where extensions are mapped to their "effective" ProgID.

    A user can explicitly choose default applications in the Settings app or (depending on the Windows version) force it when using the "Open With" feature. When the "Open With" feature has been used to set the default, the ProgId often looks like "Applications\Example.exe". This is likely in your case since the file type has no real description.

    The system is supposed to be smart enough to understand that a new application has been installed that wants to associate with an existing extension and pop up a toast or the "Open With" dialog in its "keep using" mode (depending on the Windows version). This will probably only happen once per-user for each extension and might be easy to miss while developing.

    Even querying which ProgId is the "effective" default is hard. On systems that support it, use ASSOCSTR_PROGID, otherwise fall back to IApplicationAssociationRegistration::QueryCurrentDefault.

    As an aside, if you want to be in the context menu of some extension but don't want to be the default handler, register under HKEY_LOCAL_MACHINE\Software\Classes\SystemFileAssociations\.ext instead (WinXP and later). This key is always associated with the extension, even if the ProgId changes.