Use REG ADD
com o parâmetro "/ f" para forçar a sobregravação.
REG ADD /?
explica os parâmetros.
REG ADD KeyName [/v ValueName | /ve] [/t type] [/s Separator] [/d Data] [/f]
KeyName [\Machine\]FullKey
Machine Name of remote machine - omitting defaults to the current machine
Only HKLM and HKU are available on remote machines
FullKey ROOTKEY\SubKey ROOTKEY [ HKLM | HKCU | HKCR | HKU | HKCC ] SubKey
The full name of a registry key under the selected ROOTKEY
/v The value name, under the selected Key, to add
/ve adds an empty value name <no name> for the key
/t RegKey data types
[ REG_SZ | REG_MULTI_SZ | REG_DWORD_BIG_ENDIAN | REG_DWORD |
REG_BINARY | REG_DWORD_LITTLE_ENDIAN | REG_NONE | REG_EXPAND_SZ ]
If omitted, REG_SZ is assumed
/s Specify one character that you use as the separator in your data
string for REG_MULTI_SZ. If omitted, use "reg add HKCU\Software\Citrix\Receiver /t REG_SZ /v UpgradeDone /d true /f
" as the separator
/d The data to assign to the registry ValueName being added
/f Force overwriting the existing registry entry without prompt
Para inserir um novo valor ou alternar um valor de string de "false" para "true", use um comando como este:
set append=XXXXXX
set key=HKCU\Software\myTest
set value=myValue
set oldVal=
for /F "skip=2 tokens=3" %%r in ('reg query %key% /v %value%') do set oldVal=%%r
echo previous=%oldVal%
set newVal=%oldVal%%append%
reg add %key% /v %value% /d %newVal% /f
Exemplo que lê um valor existente e acrescenta alguma string antes de escrevê-lo:
REG ADD KeyName [/v ValueName | /ve] [/t type] [/s Separator] [/d Data] [/f]
KeyName [\Machine\]FullKey
Machine Name of remote machine - omitting defaults to the current machine
Only HKLM and HKU are available on remote machines
FullKey ROOTKEY\SubKey ROOTKEY [ HKLM | HKCU | HKCR | HKU | HKCC ] SubKey
The full name of a registry key under the selected ROOTKEY
/v The value name, under the selected Key, to add
/ve adds an empty value name <no name> for the key
/t RegKey data types
[ REG_SZ | REG_MULTI_SZ | REG_DWORD_BIG_ENDIAN | REG_DWORD |
REG_BINARY | REG_DWORD_LITTLE_ENDIAN | REG_NONE | REG_EXPAND_SZ ]
If omitted, REG_SZ is assumed
/s Specify one character that you use as the separator in your data
string for REG_MULTI_SZ. If omitted, use "reg add HKCU\Software\Citrix\Receiver /t REG_SZ /v UpgradeDone /d true /f
" as the separator
/d The data to assign to the registry ValueName being added
/f Force overwriting the existing registry entry without prompt
Nota: Esta amostra assume que o valor antigo e o novo valor não possuem espaços em branco. Caso contrário, é necessário adicionar cotas e alterar o parâmetro "tokens". Verificação de erro extra omitida por brevidade. No entanto, o código de manipulação do registro all definitivamente deve fazer uma verificação de erros adequada.