How can I append data to a Windows registry value in a batch file?
reg.exe
seems to only support create/delete keys and values - I want to take an existing REG_MULTI_SZ
value and append some more data to it.
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.
Sign up to join this communityHow can I append data to a Windows registry value in a batch file?
reg.exe
seems to only support create/delete keys and values - I want to take an existing REG_MULTI_SZ
value and append some more data to it.
If you have git and thus git bash then you could use a shell script instead. Here is a function that will append an argument to the Path registry key value.
function append_path(){
tpath=$(reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" //v Path | grep -oP "%System.*")
tpath="$tpath;$1"
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" //v Path //t REG_EXPAND_SZ //d "$tpath" //f
}
The double slashes may not be necessary, but in my experience I've found I need them for some commands to function correctly in a bash shell.
To use it, you would simply write
append_path C:/tools/bin
And of course if the path has spaces you'll need to provide quotations or the function will interpret anything following a space as a new argument. Of course you'll need to ensure the path is in a windows format. So if your script is acquiring the paths for you, you'll need to convert them. There are scripts written that do this, but that is for another SO question.