Walker News

Windows Registry Command Line Tool: The Reg Escape Character

What are the reg.exe escape characters for using double quotation marks (“) and ampersand (&) in the string data? Well, after number attempts of trial and error, I found at least TWO escape characters of this Windows Registry command line tool (maybe more than that; if you know of any, kindly comment).

Since Windows Vista, I tried to find ways of using reg.exe, a.k.a. Registry Manipulation Utility, to apply various Registry hacks in Windows command shell to unleash hidden, undocumented features.

However, using reg command to add elevated Command Prompt shortcut in the right click context menu really bugged me, as I couldn’t figure out on how to tell reg.exe to escape double-quote and ampersand used in the string value :-(

Now, I got two and they are good to apply that particular Registry hack for opening Command Prompt window with right click :-), as written in previous post.

For example, take notes on the character in red:
reg add HKCR\Directory\shell\Runas\Command /ve /t REG_SZ /d "cmd.exe /k \"pushd %L ^&^& title Elevated Command Prompt Window\"" /f

where backslash (\) is used to escape double-quote in string value and the caret (^) is used to escape each of the ampersands that follow the escaped double-quote.

Custom Search

  1. Ianus 10-04-10@08:00

    Shouldnt one write ^%%L instead of %L? In a script %L will be interpreted as L and in the registry instead of %L you will just have L… E.g.

    REG ADD “HKCR\Directory\shell\cmd\command” /ve /d “cmd.exe /k \”cd ^%%L\”” /f

    will be executed as

    REG ADD “HKCR\Directory\shell\cmd\command” /ve /d “cmd.exe /k \”cd %L\”” /f


    REG ADD “HKCR\Directory\shell\cmd\command” /ve /d “cmd.exe /k \”cd %L\”” /f

    will be executed (interpreted) as

    REG ADD “HKCR\Directory\shell\cmd\command” /ve /d “cmd.exe /k \”cd L\”” /f

    That will have the undesired effect of putting into the registry the value

    cmd.exe /k “cd L”

    instead of

    cmd.exe /k “pushd %L”

  2. Walker 10-04-10@15:08

    While I have tested that in Windows Command Prompt directly, I never test it in Windows batch file.

    Good to know that too. Thank you.

  3. vivek 19-06-12@23:01

    Thanks! Saved me from a critical thing

  4. Tieske 05-05-13@14:40

    Looks to me as if they use the same sequences as for batch files; http://www.robvanderwoude.com/escapechars.php

2017  •  Privacy Policy