0

This is driving me bananas but it must be something very simple. I am trying to add an ImagePath Value (REG_SZ) in a Batch script using REG ADD, where the Value Data contains embedded "double quotes". But I keep getting an "Invalid Syntax" error. This is the Value I am trying to add:

Key  : HKLM\SYSTEM\CurrentControlSet\Services\MSSQL$SQLEXPRESS
Value: ImagePath REG_SZ
Data : "C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\Binn\sqlservr.exe" -sSQLEXPRESS 

I tried enclosing the Data in single quotes:

@SETLOCAL
@SET IPATH="C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\Binn\sqlservr.exe" -sSQLEXPRESS
@REG.EXE ADD "HKLM\SYSTEM\CurrentControlSet\Services\MSSQL$SQLEXPRESS" /f /v ImagePath /t REG_SZ /d '%IPATH%'

I also tried enclosing in "double quotes", bang (!), [brackets], \backslashes\ and ^carets^ but I keep getting the syntax error.

Any idea what I am doing wrong?

1 Answer 1

1

The parameter needs to be double-quoted. Other randomly chosen punctuation (single quotes, exclamation marks, ...) is not going to work.

However, you need to prefix the inner double-quotes with backslashes:

@SET ImagePath=\"C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\Binn\sqlservr.exe\" -sSQLEXPRESS
@REG.EXE ADD "HKLM\SYSTEM\CurrentControlSet\Services\MSSQL$SQLEXPRESS" /f /v ImagePath /t REG_SZ /d "%ImagePath%"

Note 1: To assign values in Cmd you need to use SET (as in SET VAR=VALUE).

Note 2: Do not use PATH as the variable name, as it is already used by Cmd for specifying program locations and overwriting it will make the script unable to run REG.EXE.

3
  • thanks for pointing out the typo and PATH misuse - fixed. Commented Jul 26, 2019 at 11:35
  • your answer made me realize that I did not post the question properly. Rather than an extensive redo, I will create a new question. Should I delete this one? Commented Jul 26, 2019 at 12:00
  • Question has been replaced by this question Commented Jul 26, 2019 at 12:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .