0
1
I have asked a question, Use an environment variable to point to an "Open With" program, which received a fantastic answer.
To add myapp.exe
, residing in %MYAPPSDIR%
, to the Open With context menu, I should write in the CLI
reg add "HKCR\Applications\myapp.exe\shell\open\command" /ve /t REG_EXPAND_SZ /d "\"^%MYAPPSDIR^%\myapp\myapp.exe\" \"^%1\"" /f
Now I want to have a .bat
file, receiving a parameter, which executes that sentence. E.g., executing regadd.bat myapp.exe
would do it. What should the line in the .bat
file be?
The points are:
- How to include the parameter,
- How to include the parameter with
.exe
removed (for the directory part), - How to avoid expanding
%1
that goes into the registry (I do not know how to escape it appropriately).
I found many resources (e.g., How to use `%` in a batch file), but I wouldn't like to tinker with the registry. My bet for 1 and 3 is (still have to work out 2):
reg add "HKCR\Applications\%1\shell\open\command" /ve /t REG_EXPAND_SZ /d "\"^%MYAPPSDIR^%\(%1 with .exe removed)\%1\" \"^%1\"" /f
I could also set the .bat
to be run as regadd.bat myapp
. In that case, the line would be
reg add "HKCR\Applications\%1.exe\shell\open\command" /ve /t REG_EXPAND_SZ /d "\"^%MYAPPSDIR^%\%1\%1.exe\" \"^%1\"" /f
I am interested in both options.
Thanks. What about point 2? – sancho.s Reinstate Monica – 2015-06-25T08:52:04.200
1
@sancho.s Use
– DavidPostill – 2015-06-25T11:17:46.883%~n1
- expands%1
to a file name without file extension. See Command Line arguments (Parameters) for this and other parameter extensions.Very thorough answer! I will check the options and post feedback. – sancho.s Reinstate Monica – 2015-06-25T16:27:01.953
Feedback #1: I do not know why you set 3 levels of "worthiness" for your solutions (perhaps you could comment on the reasons). At any rate, for the intended use, as posted in the OP, I found the first one is useful, since it allows for extracting the app name without .exe, for later use. The following two alternatives only detect if .exe is present, but they do not isolate the app name. – sancho.s Reinstate Monica – 2015-07-30T10:44:06.940
@DavidPostill - Your comment is worth an answer. – sancho.s Reinstate Monica – 2015-07-30T10:49:43.620
I have added a summarizing answer below, showing the appropriate line of code, http://superuser.com/a/947474/245595
– sancho.s Reinstate Monica – 2015-07-30T11:15:25.703