April 7, 201214 yr Guys, can you tell me where exactly do I NEED to use double backslashes please? I tried to google it up and didn't get any definite answer. I never used it once and never had a problem. Various sources say I MUST use double backslashes in scripts, but that's quite general statement. Never had problems using single backslash in .reg files, batch files, or unattended one.
April 7, 201214 yr Well it depends on the context but generally speaking that is the syntax that an application needs to properly parse the input.
April 7, 201214 yr Hm. I always used it in batch files and .reg files without problems. Never used it in unattended answer file either. Everything always worked...
April 7, 201214 yr It's more a factor of what other pieces of software are involved - not just batch and .reg files by themselves which in general do not require double backslashes. There are other utilities that use the backslash as an escape character. For example, you might have seen references to "\n" being used to represent a "new line"? This is true in all the various versions of C, C++, etc. Anyway, since the backslash is used as an escape character, then if you really wanted to use a backslash as a backslash, you have to double it up, ie escape the escape character. I usually see doubled backslashes used for code that is run during Windows installation routines, since many of those routines are written in C++. But someone else will need to give you better specifics. I can just tell you the "why", not the "when". Sorry.Cheers and Regards
April 8, 201214 yr Various sources say I MUST use double backslashes in scriptsCan you name a example?Never had problems using single backslash in .reg files,A Reg_sz entry uses double backslashes at path.[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Browser]"DisplayName"="@%systemroot%\\system32\\browser.dll,-100" batch filesA regular expression search string may use double backslashes to escape a single backslashhttp://technet.microsoft.com/en-us/library/bb490907.aspx
April 8, 201214 yr Can't name any specific, just people on forums and articles I read in past...Fair enough with the registry, but why does it work with single backslash as well?example: reg add HKLM\Software\Microsoft\Windows\CurrentVersion\Themes /v InstallTheme /t REG_SZ /d "%SystemDrive%\Windows\Resources\Themes\AeroNoBackground.theme" /f
April 8, 201214 yr why does it work with single backslash as well?This example uses reg.exe to set a entry.Reg.exe is another application with own rules: single backslash is appropiateThis is not a .reg file.
April 8, 201214 yr if I export a reg key and it has the \\ then I simply use that.Here is perfect example where if you don't then it won't work.First reg file that works[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\Background\shell\Kill Not Responding Tasks\command]@="C:\\Windows\\System32\\taskkill.exe /F /FI \"STATUS eq NOT RESPONDING\""Now we remove \\ and it say it import but you open key and it is blank[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\Background\shell\Kill Not Responding Tasks\command]@="C:\Windows\System32\taskkill.exe /F /FI \"STATUS eq NOT RESPONDING\""EDIT: You must delete key before second import to see thisCase closed? Edited April 8, 201214 yr by maxXPsoft
April 8, 201214 yr Now I understand, I guess you need to use the double backslash for setting theme registry as the default registry is like this:Windows Registry Editor Version 5.00[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes]"Drop Shadow"="FALSE""Flat Menus"="FALSE""SetupVersion"="10""InstallTheme"="C:\\Windows\\resources\\Themes\\aero.theme""InstallVisualStyle"="%ResourceDir%\\themes\\Aero\\Aero.msstyles"
April 8, 201214 yr Now I understand, I guess you need to use the double backslash for setting theme registry as the default registry is like this:I had not tampered with that theme key but I exported same key and it does contain \\ as default.There are certain keys that won't work unless you \\. I have no explanation but if you export and they contain then you best use them.
April 8, 201214 yr Now I understand, I guess you need to use the double backslash for setting theme registry as the default registry is like this:It's not about theme. It's about a file name with a path. This goes to all folder file names."InstallVisualStyle"="%ResourceDir%\\themes\\Aero\\Aero.msstyles"Seems to be a default bug: a RegSz dosn't expand a %ResourceDir% entry.
April 8, 201214 yr Seems to be a default bug: a RegSz dosn't expand a %ResourceDir% entry.hadn't noticed that till you said something.Type set in a cmd prompt. There is no %ResourceDir%Google returns nothing on it eitherMS Bug for sure. Edited April 9, 201214 yr by maxXPsoft
April 9, 201214 yr %ResourceDir% is internal Windows thing. Doing a file content search I find this in many files. Edited April 9, 201214 yr by maxXPsoft
April 9, 201214 yr I don't doubt %ResourceDir%. I doubt the type Reg_SZ.A XP themeui.dll sets HKLM,"Software\Microsoft\Windows\CurrentVersion\Themes\VisualStyleDirs","1",%REGEXSZ%,"%%ResourceDir%%\Themes"This setting exist at Windows 7 too.That's type Reg_Expand_SZ to %ResourceDir%.Can anybody clarify this?Which part uses %ResourceDir% ? Which part expand the string?
Create an account or sign in to comment