1

Everybody say that \ works as an escape inside reg.exe like:

The REG command will interpret \ as an escape for the character that immediately follows it. source

but I found it not a full correct rule. see this examples please:

escaping a character does not work:

reg add HKCU\testt /f /v "" /t REG_EXPAND_SZ /d "a\b"
===> a\b

escaping the escape does not work:

reg add HKCU\testt /f /v "" /t REG_EXPAND_SZ /d "a\\b"
===> a\\b

reg add HKCU\testt /f /v "" /t REG_EXPAND_SZ /d "a\\b" ===> a\\b

but when I escape a double quote " then escaping the escape will work:

reg add HKCU\testt /f /v "" /t REG_EXPAND_SZ /d "a\\\"b"
===> a\"b

conclusion: \ works as an escape only if I escape a double quote "

and more strange is this, escape the escape does not work even when I escape a double quote:

reg add HKEY_CURRENT_USER\testt /f /v "" /t REG_EXPAND_SZ /d "a\\ \"b"
===> a\\ "b

this means that to escape the escape it have to be adjacent to the escaped double quote!!

is this a correct behavior? where is this documented if it is correct?

the examples were done on win7 using cmd.

1 Answers1

0

but I found it not a full correct rule. see this examples please:
... escaping a character does not work:

reg add HKCU\testt /f /v "" /t REG_EXPAND_SZ /d "a\b"
===> a\b

I don't see where you understood and/or read the rule that states that the escape must be used to escape itself when used under double quotes.

All of your examples work as expected and below are the same end there is nothing wrong with the results.

reg add HKCU\testt /f /v "" /t REG_EXPAND_SZ /d a\\b
===> a\\b

reg add HKCU\testt /f /v "" /t REG_EXPAND_SZ /d a\b ===> a\b

reg add HKCU\testt /f /v "" /t REG_EXPAND_SZ /d ""a\b"" ===> "a\b"

reg add HKCU\testt /f /v "" /t REG_EXPAND_SZ /d ""a\b"" ===> "a\b"

reg add HKCU\testt /f /v "" /t REG_EXPAND_SZ /d \"a\b\" ===> \a\b

See Escape Characters by @Rob Vander Woude

Io-oI
  • 9,237