Add Registry Key Data With Quotes

时间:2015-05-12 22:32:49

标签: windows batch-file registry add-in

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:

>>> df[0:6].groupby(['X']).count() + df[6:].groupby(['X']).count()
    Y
X    
A   2
B   4
C   4
D   2

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:

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

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 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 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...

1 个答案:

答案 0 :(得分: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