0

I have written a batch that adds a new registry value under a specified key. The data value is a file path and must have outer quotes like so:

"C:\Program Files\Microsoft Office\Office15\Library\Custom_AddIn.xlam"

enter image description here

But even when using escape characters to keep the quotes, the closest I've been able to get is this (missing first quote):

C:\Program Files\Microsoft Office\Office15\Library\Custom_AddIn.xlam"

using this code:

setlocal enableDelayedExpansion
setlocal ENABLEEXTENSIONS

SET VERSION=15.0
SET PATH="C:\Program Files\Microsoft Office\Office15\Library\Custom_AddIn.xlam"

REG add HKEY_CURRENT_USER\Software\Microsoft\Office\%VERSION%\Excel\Options /v OPEN /t REG_SZ /d %PATH%^" /f

If I try to add the carrot and quote to the beginning of the path, the batch doesn't add the value at all.

I've also tried using \ to keep the quotes to the same effect: one at the end keep the last quote, one at the beginning keeps the value from being added altogether.

What am I doing wrong here? According to the answers to this question, what I'm doing should work...

Community
  • 1
  • 1
ARich
  • 3,230
  • 5
  • 30
  • 56

1 Answers1

0

Quotes need to be escaped on declaration when setting the variable and you should also put \" around the %PATH%, like this:

setlocal enableDelayedExpansion setlocal ENABLEEXTENSIONS

SET VERSION=15.0 SET PATH=\"C:\Program Files\Microsoft Office\Office15\Library\Custom_AddIn.xlam\"

REG add HKCU\Software\Microsoft\Office\%VERSION%\Excel\Options /v OPEN /t REG_SZ /d "%PATH%" /f

  • I get an error `ERROR: Invalid syntax.` when I implement your suggestion. Any thoughts as to why this is? – ARich May 13 '15 at 13:30
  • I've tried the exact commands and it worked on my Windows 7 PC. I suggest you to **create a .bat** file with the same lines and execute it, you will **see the /d "%PATH%" with the replaced string**, then adjust accordingly. I hope this help. – Jonathan Larouche May 13 '15 at 14:48
  • I copied your code and made a new .bat file. The file wouldn't run for me...still throws the `ERROR: Invalid Systax` error. I also have a Win7 64-bit machine. – ARich May 13 '15 at 16:16
  • When I executed it was changing the path to something without spaces. If your path use spaces then you should escape the " with \". I've edited the script above – Jonathan Larouche May 13 '15 at 17:43