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.
cmd.exe(the second half of this answer of mine) make me kinda expect all kinds of weirdness in this subject. Your question did not surprise me. Good luck. – Kamil Maciorowski May 03 '23 at 06:51cmd, I usedRunfrom start menu (win+R) and the examples above gave the same results. the problem is with howreg.exeworks and interpret \ . I do not thinkpowershellwill be different. – Badr Elmers May 03 '23 at 15:55