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.

Badr Elmers
  • 223
  • 2
  • 9
  • 1
    Side note: this old article [*Why the Windows Registry sucks … technically*](https://rwmj.wordpress.com/2010/02/18/why-the-windows-registry-sucks-technically/) plus what I know about `cmd.exe` (the second half of [this answer of mine](https://superuser.com/a/1762573/432690)) 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:51
  • Honestly, just use PowerShell. Why go through this pain of a syntax? – Destroy666 May 03 '23 at 15:03
  • @Kamil Maciorowski thank you for the articles, I never saw the windows registry as a filesystem. an interesting article. – Badr Elmers May 03 '23 at 15:48
  • @Destroy666 it is not a problem of syntax or `cmd`, I used `Run` from start menu (`win+R`) and the examples above gave the same results. the problem is with how `reg.exe` works and interpret \ . I do not think `powershell` will be different. – Badr Elmers May 03 '23 at 15:55
  • 2
    The registry dates since several decades ago and has changed very little. The code is full of strange code and decisions by developers that are no longer in Microsoft, and the possibilities for destroying Windows installation frighten new developers away. So you get what you get, and don't ask for explanations. Rather be thankful that it still sort-of works. – harrymc May 03 '23 at 20:23

0 Answers0