Windows file associations done properly?

假装没事ソ 提交于 2019-12-02 10:55:43

Old question -- no answer for 7.5 months -- but the following might help future googlers (like me).

HKEY_CLASSES_ROOT is a combined view of

  • HKEY_LOCAL_MACHINE\Software\Classes
  • HKEY_CURRENT_USER\Software\Classes.

You're not supposed to write to HKEY_CLASSES_ROOT, just use it read-only. Also, the recommended practice is to write to HKEY_CURRENT_USER\Software\Classes rather than HKEY_LOCAL_MACHINE, unless you really need to set things for all users.

Microsoft's documentation seems rather verbose and scattered, so it's taking me a long time to get settled on exactly what i need to do for my own little app. But still, it may be best to first try the official documentation (unless someone can point us to a place that explains things better), and ask questions later if one can't make sense of it.

The entry point for Microsoft's documentation about this area is "Desktop app technologies" at https://msdn.microsoft.com/library/windows/desktop/bg126469.aspx

For file-type registration, it led me to "Implementing a Custom File Format" at https://msdn.microsoft.com/en-us/library/windows/desktop/ff521657(v=vs.85).aspx

From there go into "File Types and File Associations", and from there the sub-menus cover everything you'll need (and more).

Remember to write to HKCU\Software\Classes. It seems like when HKEY_CLASSES_ROOT (HKCR) is written in the docs, it's often just as a convenient way of referring to (HKCU|HKLM)\Software\Classes.

About "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\App Paths" or "HKEY_CLASSES_ROOT\Applications":

The MS docs explain how they relate to the keys you've already used. (I'm still getting my head around it, so can't offer a more straightforward explanation.)

Some places seem to say "App Paths" is preferred, but actually you may need to use both, because "App Paths" really is only about paths, and things like SupportedTypes and FriendlyAppName are only in "HK(LM|CU)\Classes\Applications".

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!