REG ADD Ignores /f

7,699

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:

@ECHO OFF

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

START RegEdit
Share:
7,699

Related videos on Youtube

Kevin Jones
Author by

Kevin Jones

Updated on September 18, 2022

Comments

  • Kevin Jones
    Kevin Jones almost 2 years

    My script:

    @ECHO OFF
    
    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
    
    START RegEdit
    

    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?

    • harrymc
      harrymc about 7 years
      Try to use reg import.
  • airstrike
    airstrike about 7 years
    Thanks. Quotes in batch/bash scripts are truly the one thing I hate the most in computing.
  • Kevin Jones
    Kevin Jones about 7 years
    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