How to associate a file extension to a program without making it the default program

丶灬走出姿态 提交于 2019-12-19 06:39:15

问题


I'm deploying a small conversion tool on some systems, and want the users to be able to run it from the right click Open with menu. But I don't want to change the default program users have associated to this file type.

It is easy to associate a file extension/type to a program, but how to do it (programatically of course) without changing the default program?


回答1:


Setting the following keys worked for me:

key HKLM/SOFTWARE/Microsoft/Windows/CurrentVersion/App Paths/<progname>: "" = <appPath>

key HKCR/Applications/<progname>/SupportedTypes: <fileExt> = ""
key HKCR/<fileExt>: "" = <progID>

key HKCR/<progID>/OpenWithList/<progName>
key HKCR/<fileExt>/OpenWithList/<progName>
key HKCR/SystemFileAssociations/<fileExt>/OpenWithList/<progName>

delete key and subkey at HKCU/SOFTWARE/Microsoft/Windows/CurrentVersion/Explorer/fileExts/<fileExt>



回答2:


You can add scripts to the context menu (below Open with) by adding it in the windows registry:

  1. Open regedit
  2. Goto HKEY_CLASSES_ROOT\your_class\Shell
  3. Add a new key and give it a name
  4. Edit the (Default) value of this key and insert the text you want to show in the context menu
  5. Add a new key named Command under your newly created key
  6. Edit the (Default) value of this key and insert the command you want to execute
  7. Enjoy!



回答3:


In the "File Types" Windows Dialog you can click "Advanced" on your file type and there create a custom action tied to your application.

Possibly you can also find a way to do this in a programmatic manner, or at least create a .REG file with the equivalent registry options.




回答4:


I have achieved the correct FILE ASSOCIATION using these cmd commands. (just an example):

REG ADD "HKEY_CLASSES_ROOT\Applications\notepad++.exe\shell\open\command" /v @ /t REG_SZ /d "\"C:\\Program Files\\Noteepad++\\notepad++.exe\" \"%1\"" /f
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.txt" /v "Application" /t REG_SZ /d "notepad++.exe" /f
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.txt\OpenWithList" /v "g" /t REG_SZ /d "notepad++.exe" /f

assoc .txt=MyCustomType
ftype MyCustomType="C:\Program Files\Noteepad++\notepad++.exe" "%1"

(it's better to put them in .bat file)




回答5:


here's a worked example for XP adding a command prompt option to folders. Create a .reg file

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\Command Prompt]

[HKEY_CLASSES_ROOT\Directory\shell\Command Prompt\command] @="cmd.exe /k cd \"%1\""



来源:https://stackoverflow.com/questions/2956122/how-to-associate-a-file-extension-to-a-program-without-making-it-the-default-pro

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