See [1] for the description of HKLM, HKCU, and HKCR. According to [2], HKCR provides a merged view of HKCU and HKLM. For ProgID, see [3]. For file extension, see [5].
File extensions config examples (see [7] for valid keys/entries):
for .rar:
- HKLM/SOFTWARE/Classes/.rar has a key "(Default)" with ProgID "7-Zip.rar"
- HKCU/Software/Microsoft/Windows/CurrentVersion/Explorer/FileExts/.rar
- child: OpenWithProgids has a key named "7-Zip.rar" (appear in "open with" menu)
- HKLM/SOFTWARE/Classes/.txt (apply to all users)
- keys: (Default)=txtfile; Content Type=text/plain (txtfile is ProgID)
- child: OpenWithProgids (appear in "open with" menu)
- child: ShellNew
- HKCU/SOFTWARE/Classes/.txt (apply to the interactive user)
- Does not exist in my case
- HKCU/Software/Microsoft/Windows/CurrentVersion/Explorer/FileExts/.txt (apply to the interactive user)
- child: OpenWithProgids has a ProgID "txtfile"
- child: UserChoice has a key named "Progid" with value "Applications/notepad++.exe" (!important)
Applications with ProgID:
- HKLM/SOFTWARE/Classes/7-Zip.rar/shell/open/command (7-Zip.rar is ProgID)
- HKLM/SOFTWARE/Classes/txtfile/shell/open/command: the value of "(Default)" is the command used to open files.
How a file extension (e.g. .txt) is mapped to a file type?
- "UserChoice" takes the first precedence. If it is not set, key "(Default)" stores the ProgID which can be found under [HKCU|HKLM}/SOFTWARE/Classes/.
For gvim.exe, you should have HKLM/SOFTWARE/Classes/Applications/gvim.exe/shell:
- edit/command[(Default)] = command
- open/command[(Default)] = command
Notes: "gvim.exe" is ProgID, see [3] for more detail.
How to change the default app when a file is double-clicked? (Take .c as an example)
- Solution 1 (use entries for Explorer)
- For HKCU/Software/Microsoft/Windows/CurrentVersion/Explorer/FileExts/.c/UserChoice, set the value of key "UserChoice" to "Applications/gvim.exe".
- For HKLM/SOFTWARE/Classes/Applications/gvim.exe/shell/edit/command, set the value of key "(Default)" to '"C:\Program Files (x86)\Vim\vim73\gvim.exe" -p --remote-tab-silent "%1" "%*"'
- Open "Control Panel\Programs\Default Programs\Set Associations", you will see .txt has been associated with gvim.exe.
- Solution 2
UserChoice should not be set in this solution (you can delete it first). - make sure HKLM/SOFTWARE/Classes/.c has the key "(Default)" set to "cfile".
- For HKLM/SOFTWARE/Classes/cfile/shell/open/command, set "(Default)" to the gvim command above.
References
[1] http://msdn.microsoft.com/en-us/library/windows/desktop/ms724475%28v=vs.85%29.aspx[2] http://msdn.microsoft.com/en-us/library/windows/desktop/ms724498%28v=vs.85%29.aspx
[3] http://msdn.microsoft.com/en-us/library/windows/desktop/dd542719%28v=vs.85%29.aspx
[4] http://msdn.microsoft.com/en-us/library/windows/desktop/ms690440%28v=vs.85%29.aspx
[5] http://msdn.microsoft.com/en-us/library/windows/desktop/ms678415%28v=vs.85%29.aspx
[6] http://msdn.microsoft.com/en-us/library/windows/desktop/hh127445%28v=vs.85%29.aspx
[7] http://msdn.microsoft.com/en-us/library/windows/desktop/cc144148%28v=vs.85%29.aspx#fa_optional_keys_attributes
Sample reg file
Be careful, it will overwrite the current value!!!
============================================
Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.c] @="cfile" [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\cfile\shell\open\command] @="\"C:\\Program Files (x86)\\Vim\\vim73\\gvim.exe\" -p --remote-tab-silent \"%1\" \"%*\""============================================
Note: the value must be a string put in double quotations!