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.