Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows: Changing the name/icon of an application associated with a file type

I would like to associate a file type in Windows with a particular application, but I need to make it so when the user opens the "Open With" menu, the name and icon of the application in the list is customized for that file type (i.e., not simply the name and icon of the executable).

This is because the binary is a general binary that runs many different apps, depending on its command-line arguments (similar topython.exe or javaws.exe). I don't want the "Open With" menu to show "Python" or "Java", I want it to show the name and icon for the application that is being passed on the command-line.

I know how to add file associations (by creating a ProgID in HKEY_CLASSES_ROOT, and adding the ProgID name to either OpenWithProgids or HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts), but I cannot find any way to change the name or icon of the application as it appears in the "Open With" menu for files of that type. Is this possible?

(Edited to clarify my existing understanding of adding file associations.)

like image 297
mgiuca Avatar asked Oct 22 '22 08:10

mgiuca


1 Answers

I have a partial solution which allows the name to be set (but not the icon or company name).

It is possible to register an application in Windows. This is very similar to creating a ProgID, but it allows you to set the FriendlyAppName. For some reason, you can't set the FriendlyAppName on a ProgID. Unfortunately, FriendlyAppName is not a string, but a reference to a resource in a .DLL or .EXE file. Go figure.

So:

  • Create a dummy .dll file for the virtual application with which you want to associate the file. It doesn't have to have any code in it, just resources. Give it a string resource containing the title of the application.
  • Create a key HKEY_CLASSES_ROOT\Applications\whatever.exe (whatever should be a unique name specific to the virtual application -- it does not need to be the name of a real executable, but it does need to end in .exe or another executable extension).
    • Set the default value, DefaultIcon and shell, as described in Programmatic Identifiers. This sets the name and icon for the file type when this association is the default, as well as the shell command to run.
    • Also give it a FriendlyAppName value referring to the dummy .dll. For example, if your app name string is string number 23, set FriendlyAppName to "@PATH\TO\DLL.dll,-23".
    • Add a SupportedTypes key and add a value for each type that the virtual application can handle.

Now the application will appear in the "Other Programs" dropdown of the "Choose default program" dialog, but not in the "Open With" menu. To properly associate it, you need to:

  • Go to the file extension's entry in the registry. This should be in HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts (it can also be in HKEY_CURRENT_USER, but I have found that the FileExts version overrides, and Windows creates one there if the user manually creates a file association, so best to use that one).
    • Under OpenWithList, there needs to be an entry for the fake whatever.exe you created above. This should be a value whose name is an arbitrary letter and whose value is the fake exe name.
    • Also under OpenWithList, you need to ensure that the MRUList value includes the letter you assigned to the fake executable in the previous step.
    • I don't believe you need to add it to OpenWithProgids (it works without this), but the documentation tells you to.
    • To make it the default handler, under UserChoice, set Progid to "Applications\whatever.exe". This is optional, but there needs to be something set here (if UserChoice is missing, nothing will work).

Lastly, hit it with a SHChangeNotify to refresh Windows' icon and shortcut cache. (I'm not sure if this is necessary after all; I just noticed that it helps to make Windows notice the changes you're making.)

Now on the "Open With" menu for the file type, you should see an entry for the custom string you put in the dummy .dll. It will still have the icon of the real binary mentioned in the shell command, but you can at least control the name. Why, why is this so hard?

I will leave this question open for awhile in case there are better answers.

like image 64
mgiuca Avatar answered Oct 24 '22 10:10

mgiuca