I have the following problem on Windows 7. I am trying to create a context menu for right clicking files of a specific type, let us say *.hyb, i.e. I want, when I right click on this kind of files (like filename.hyb), an option in the menu like "Run with Myapplication", and when I click on it I want that the command "Myapplication.exe filename" to be run.

I have managed to create the context menu for this specific file, but the problem is the filename is passed as an argument to Myapplication.exe with its extension. Myapplication.exe cannot handle file-extensions, so I need to remove it. My registry key (stored under HKEY_CURRENT_USER\Software\Classes\hyb_auto_file\shell\Myapplication\command) has the value C:\SomeFolder\Myapplication.exe %1

Can I tweak the %1 parameter so that the filename is passed without its extension?

Thank you very much!

  • Change Myapplication.exe to work with full filenames (with extension). – Werner Henze Dec 19 '13 at 10:03
  • @ Werner Henze: I would, but I want to be backwards compatible with older versions of Myapplication, which I am not allowed to change. – Christos Liontas Dec 19 '13 at 10:57
  • No chance to support both formats: files with and without extension? Maybe by providing an additional parameter like "/withext"? This looks a bit cleaner to me than the (working) workaround with the call to cmd (which came to my mind, but was too dirty for me). – Werner Henze Dec 19 '13 at 11:11
  • @ Werner Henze: The problem is that the older (untouchable) version of the program is not able to work with extensions, not the newer one. – Christos Liontas Dec 19 '13 at 11:49

It does not work to write "%~dpn1" in the registry.

You could call a CMD command file which chops off the extension and calls your application:

Content of file hyb.cmd:

echo on

myApp.exe "%~dpn1"

"%~dpn1" will take drive+path+name of parameter 1 and leave out the extension.

Registry definition file hyb.reg to call this script:

Windows Registry Editor Version 5.00



[HKEY_CLASSES_ROOT\.hyb\shell\open hyb file]

[HKEY_CLASSES_ROOT\.hyb\shell\open hyb file\command]
@="cmd.exe /c hyb.cmd \"%1\""

Note that Windows provides useful commands to maintain file associations from the commandline without touching the registry. Ask Google for ASSOC and FTYPE.

  • Thank you very much for your answer! It worked, although I had to use the simpler key "C:\somePath\hyb.cmd" "%1". I don't know why your key didn't work, I got the message that Windows couldn't find the path or that I didn't have enough rights to perform the operation. Anyway, I am very grateful! -Christos – Christos Liontas Dec 19 '13 at 10:54
  • My registry parameter assumes that script file hyb.cmd is on the search PATH. If you explicitely add the full path, you are on the safe side. – Axel Kemper Dec 23 '13 at 23:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.