8

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?

CharlesB
  • 86,532
  • 28
  • 194
  • 218

5 Answers5

5

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>
CharlesB
  • 86,532
  • 28
  • 194
  • 218
1

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!
Marc
  • 3,550
  • 22
  • 28
  • That's also what I tried before, but in my case it's not sufficient; the default association was made by hand in Explorer, and for some reason it blocks this file handling. – CharlesB Jun 02 '10 at 12:40
0

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)

T.Todua
  • 53,146
  • 19
  • 236
  • 237
0

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.

ob1
  • 1,721
  • 10
  • 25
  • Yes I want to do it programmatically – CharlesB Jun 02 '10 at 09:30
  • You can use the Win32 registry functions - http://msdn.microsoft.com/en-us/library/ms724875(VS.85).aspx - to create/change the relevant registry entries – ob1 Jun 02 '10 at 11:35
-2

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\""

Wudang
  • 553
  • 3
  • 17