My script:


SET RegPath="HKEY_CURRENT_USER\Software\Microsoft\VBA\7.0\"

REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit" /v LastKey /t REG_SZ /d "%RegPath%" /f


Despite the inclusion of /f, I am always prompted to replace the entry. How can I get the REG ADD command to not prompt and just replace the entry?

  • Try to use reg import.
    – harrymc
    Apr 11, 2017 at 19:56

1 Answer 1


If you run it as is, you'll see that the value added to the registry is actually HKEY_CURRENT_USER\Software\Microsoft\VBA\7.0" /f -- including an orphaned quotation mark, and the /f that was intended as a separate argument.

The problem here is that you're adding too many quotes via the variable itself, not to mention in the call to the variable, and as such it's confusing Reg about where arguments begin and end.

Remove all those extraneous quotation marks, and it works as intended:


SET RegPath=HKEY_CURRENT_USER\Software\Microsoft\VBA\7.0\

REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit" /v LastKey /t REG_SZ /d %RegPath% /f

  • Thanks. Quotes in batch/bash scripts are truly the one thing I hate the most in computing.
    – airstrike
    Apr 11, 2017 at 20:16
  • 1
    Argh! That was sort of the issue. Actually, it was two separate issues. One was the trailing backslash in the second line is interpreted as an escape character. I do need one set of quotes in the event there are spaces in the /d parameter. This is what I ended up with that works: SET RegPath=blah REG ADD ... /d "%RegPath%" /f Apr 12, 2017 at 20:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.