Is it possible to modify a registry value (whether string or DWORD) via a .bat/.cmd script?
This question is related to
windows
batch-file
cmd
automation
registry
Yes. You can use reg.exe which comes with the OS to add, delete or query registry values. Reg.exe does not have an explicit modify command, but you can do it by doing delete and then add.
Yes, you can script using the reg
command.
Example:
reg add HKCU\Software\SomeProduct
reg add HKCU\Software\SomeProduct /v Version /t REG_SZ /d v2.4.6
This would create key HKEY_CURRENT_USER\Software\SomeProduct
, and add a String value "v2.4.6" named "Version" to that key.
reg /?
has the details.
In addition to reg.exe, I highly recommend that you also check out powershell, its vastly more capable in its registry handling.
@Franci Penov - modify is possible in the sense of overwrite with /f
, eg
reg add "HKCU\Software\etc\etc" /f /v "value" /t REG_SZ /d "Yes"
You can make a .reg file and call start on it. You can export any part of the registry as a .reg file to see what the format is.
Format here:
http://support.microsoft.com/kb/310516
This can be run on any Windows machine without installing other software.
This is how you can modify registry, without yes or no prompt and don't forget to run as administrator
reg add HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\etc\etc /v Valuename /t REG_SZ /d valuedata /f
Below is a real example to set internet explorer as my default browser
reg add HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\https\UserChoice /v ProgId /t REG_SZ /d IE.HTTPS /f
/f Force: Force an update without prompting "Value exists, overwrite Y/N"
/d Data : The actual data to store as a "String", integer etc
/v Value : The value name eg ProgId
/t DataType : REG_SZ (default) | REG_DWORD | REG_EXPAND_SZ | REG_MULTI_SZ
Learn more about Read, Set or Delete registry keys and values, save and restore from a .REG file. from here
Source: Stackoverflow.com