Reputation: 707
I'm trying to use the reg add
command (reg.exe) to write to the registry, but if the value already exists I don't want to overwrite it. Without the /f
option it asks for confirmation, which I don't want. With /f
it overwrites the value, which I also don't want.
Is there an easy way to add a registry value if it doesn't exist but leave it alone if it does, and not prompt the user?
Upvotes: 1
Views: 1715
Reputation: 38708
As per my comment…
Because you have reported having to decline the overwrite prompt, I would suggest you pipe the expected N
into your REG
command:
Echo N|Reg Add "HK…… >Nul
Upvotes: 1
Reputation:
As reg returns errorlevels it can be as simple as
(using conditional execution on &&
success or ||
fail )
reg query "hkcu\console" /V ColorTable15 >NUL 2>&1 &&( echo Val exists) ||(echo Val not there)
Val exists
reg query "hkcu\console" /V ColorTable16 >NUL 2>&1 &&( echo Val exists) ||(echo Val not there)
Val not there
Upvotes: 0