Use an environment variable to point to an "Open With" program
reg add "HKCR\Applications\myapp.exe\shell\open\command" /ve /t REG_EXPAND_SZ /d "\"^%MYAPPSDIR^%\myapp.exe\" \"^%1\"" /f
Note:
- to avoid expanding
%MYAPPSDIR%
by command line interpreter,%
percent character should be escaped by the standardCLI
escape character (^
caret):^%MYAPPSDIR^%
; - to include a quote mark
"
in the data, prefix it with thereg
escape character (\
backslash). E.g.\"
here is a quote as theREG
command will interpret\
as an escape for the character that immediately follows it.
An example (copy&paste
from my administrator command line):
C:\Windows\system32>reg query "HKCR\Applications\mspaint.exe\shell\edit\command" /ve
HKEY_CLASSES_ROOT\Applications\mspaint.exe\shell\edit\command
(Default) REG_EXPAND_SZ "%systemroot%\system32\mspaint.exe" "%1"
C:\Windows\system32>reg add "HKCR\Applications\mspaint.exe\shell\edit\command" /ve /t
REG_EXPAND_SZ /d "\"^%systemroot^%\system32\mspaint.exe\" \"^%1\"" /f
The operation completed successfully.
C:\Windows\system32>reg query "HKCR\Applications\mspaint.exe\shell\edit\command" /ve
HKEY_CLASSES_ROOT\Applications\mspaint.exe\shell\edit\command
(Default) REG_EXPAND_SZ "%systemroot%\system32\mspaint.exe" "%1"