Filename without extension as a registry key variable (windows 7)

0

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!

Christos Liontas

Posted 2013-12-19T09:14:59.490

Reputation: 3

Change Myapplication.exe to work with full filenames (with extension). – Werner Henze – 2013-12-19T10:03:44.263

@ 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 – 2013-12-19T10:57:24.843

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 – 2013-12-19T11:11:30.383

@ 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 – 2013-12-19T11:49:19.557

Answers

0

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]

[HKEY_CLASSES_ROOT\.hyb\shell]

[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.

Axel Kemper

Posted 2013-12-19T09:14:59.490

Reputation: 2 892

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 – 2013-12-19T10:54:19.390

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 – 2013-12-23T23:18:42.027