Octopuss Posted April 7, 2012 Posted April 7, 2012 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.
tain Posted April 7, 2012 Posted April 7, 2012 Well it depends on the context but generally speaking that is the syntax that an application needs to properly parse the input.
Octopuss Posted April 7, 2012 Author Posted April 7, 2012 Hm. I always used it in batch files and .reg files without problems. Never used it in unattended answer file either. Everything always worked...
bphlpt Posted April 7, 2012 Posted April 7, 2012 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
cdob Posted April 8, 2012 Posted April 8, 2012 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
Octopuss Posted April 8, 2012 Author Posted April 8, 2012 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
cdob Posted April 8, 2012 Posted April 8, 2012 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.
maxXPsoft Posted April 8, 2012 Posted April 8, 2012 (edited) 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, 2012 by maxXPsoft
nice_guy75 Posted April 8, 2012 Posted April 8, 2012 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"
maxXPsoft Posted April 8, 2012 Posted April 8, 2012 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.
cdob Posted April 8, 2012 Posted April 8, 2012 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.
maxXPsoft Posted April 8, 2012 Posted April 8, 2012 (edited) 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, 2012 by maxXPsoft
maxXPsoft Posted April 9, 2012 Posted April 9, 2012 (edited) %ResourceDir% is internal Windows thing. Doing a file content search I find this in many files. Edited April 9, 2012 by maxXPsoft
GrofLuigi Posted April 9, 2012 Posted April 9, 2012 (edited) Edit: nevermindGL Edited April 9, 2012 by GrofLuigi
cdob Posted April 9, 2012 Posted April 9, 2012 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?
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now