添加注册表项,在Windows使用批处理脚本中的数据所需的报价 [英] Adding a registry key in windows with quotes needed in the data using a batch script
问题描述
小威利斯在这里。我尝试使用批处理脚本编辑时双击一个.jar文件,它使用现有的注册表项。问题是,我试图进入数据包含引号,但我还需要报价为它被认为是一个字符串。
Little Willis here. I am trying to using a batch script to edit an existing registry key that is used when double clicking a .jar file. The issue is that the data that I'm trying to enter contains quotes but I also need quotes for it to be considered a string.
例如:
reg add "HKEY_LOCAL_MACHINE\Software\Classes\jarfile\shell\open\command" /v "" /t REG_EXPAND_SZ /d "C:\Program Files\Java\jre7\bin\javaw.exe" -jar "%1" %* /f
当我运行一个批处理脚本cmd窗口打印出错误:有太多的命令行参数
When I run that in a batch script the cmd window prints out "Error: Too many command line parameters"
因此,为了使这个简单的。我要添加注册表项以C:\\ Program Files文件\\的Java \\ jre7 \\ BIN \\ javaw.exe的罐子%1%*的数据,包括报价和1%和%*正是因为它们是不转换为任何实际语句或字符串。
So to make this simple. I want to add a registry key with "C:\Program Files\Java\jre7\bin\javaw.exe" -jar "%1" %* as the data including the quotations and the %1 and %* exactly as they are not converted to any actual statement or string.
编辑:
注册表使用此命令行字符串使用通常加入:
The registry is normally added using using this command line string:
ftype jarfile="C:\Program Files\Java\jre7\bin\javaw.exe" -jar "%1" %*
它在命令行中工作正常,但正如下面的,当我在一个批处理脚本的%1和%*不会出现使用该给出的code。
it works fine in the command line, but just as the code given below when I used this in a batch script the "%1" and %* don't appear.
推荐答案
使用反斜线逃避内心的报价,即:
Use backslashes to escape the inner quotes, i.e.:
reg add "HKEY_LOCAL_MACHINE\Software\Classes\jarfile\shell\open\command" /v "" /t REG_EXPAND_SZ /d "\"C:\Program Files\Java\jre7\bin\javaw.exe\" -jar \"%1\" %*" /f
这篇关于添加注册表项,在Windows使用批处理脚本中的数据所需的报价的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!