0

I've been trying to create a very simple windows script which almost works ("almost" explains my presence here...). I wanted to chain several commands. One of them is for adding a registry key. I've found how to do the trick with the following command :

REG ADD "HKCU\Software\Microsoft\Office\12.0\Common\DRM" /v "AdminTemplatePath" /t REG_EXPAND_SZ /d ^%LocalAppData^%\Microsoft\DRM\Templates /f 

I want to add a key named "AdminTemplatePath" which has the value "%LocalAppData%\Microsoft\DRM\Templates".

Problem is about the environment variable %LocalAppData%. When I do the REG ADD /?, it says I have to put "^" before each "%" for the command line to work (without "^", the variable would be interpreted and replaced by its absolute value).

When I type the full command in a prompt, everything works fine. I have in the value field "%LocalAppData%\Microsoft\DRM\Templates". When I copy/paste this command in my batch file, no problem when running. Systems tells me everything is fine. But actually, the value is "^\Microsoft\DRM\Templates" or "\Microsoft\DRM\Templates".

When I remove the "^" in the full command and try again, value is "C:\Users\My User\AppData\Local\Microsoft\DRM\Templates".

Does anybody know the trick to keep the environment variable as is, running the batch file ?

Thank you.

1 Answer 1

1

^ is suposed to be the escape character in batch script, but I have always had trouble with it too.

Instead, try a double percentage, enclosed in double quotes:

^%LocalAppData^%\Microsoft\DRM\Templates 

Should be

"%%LocalAppData%%\Microsoft\DRM\Templates" 

Check out http://www.robvanderwoude.com/escapechars.php for more information on escape characters in batch scripts

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. Problem solved. Thanks too for the resource site :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.