The built-in reg.exe
console tool lets you add, delete, export or save (as hive) registry keys and values. When adding registry values using the reg.exe
tool, you may be wondering how to pass data with double-quotes or environment variables and add it to the registry literally.
This article tells you how to create registry values passing double-quotes and environment variables (without expanding or resolving the folder path) using the reg.exe console tool.
Add a registry value data with double quotes using REG.exe
Consider the following case. If you need to write to the (default)
by setting its data to "d:\my projects\runx64.exe"
with double quotes, you’ll need to escape the inner double-quotes using a backslash.
Example:
REG ADD HKCR\boxfile\shell\command /ve /t REG_SZ /d "\"d:\my projects\runx64.exe\" "\"%1\""
If you don’t escape the inner double-quotes around the data, such as:
REG ADD HKCR\boxfile\shell\command /ve /t REG_SZ /d "d:\my projects\runx64.exe %1"
The command will complete successfully, but you’ll end up creating the following registry key/value without double-quotes:
Example 2:
REG ADD HKCR\boxfile\shell\command /ve /t REG_SZ /d "\"d:\my projects\runx64.exe\" -runmax "\"%1\""
Add a registry value containing expandable string data using REG.exe
To add a REG_EXPAND_SZ registry value type and pass an expandable string exactly as given (without expanding the variable), you’ll need to use the caret ^
symbol with the %
symbol.
Example:
REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v Desktop /t REG_EXPAND_SZ /d ^%USERPROFILE^%\Desktop
If you don’t use the caret symbol, as in the following command-line example:
REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v Desktop /t REG_EXPAND_SZ /d %USERPROFILE%\Desktop
The environment variable or expandable string is expanded or resolved to the folder path automatically, as shown in the following image.
Hope this article helped you pass complex command-line arguments involving double-quotes and expandable variables to the registry using the reg.exe
command-line.
One small request: If you liked this post, please share this?
One "tiny" share from you would seriously help a lot with the growth of this blog. Some great suggestions:- Pin it!
- Share it to your favorite blog + Facebook, Reddit
- Tweet it!