问题
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:
- Open regedit
- Goto
HKEY_CLASSES_ROOT\your_class\Shell
- Add a new key and give it a name
- Edit the
(Default)
value of this key and insert the text you want to show in the context menu - Add a new key named
Command
under your newly created key - Edit the
(Default)
value of this key and insert the command you want to execute - 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