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

前端 未结 2 1874
刺人心
刺人心 2021-02-10 01:58

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 app

2条回答
  •  闹比i
    闹比i (楼主)
    2021-02-10 02:39

    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.

提交回复
热议问题