Adding a registry key to windows with quotes required in the data using the script package

Little Willis is here. I am trying to use a batch script package to edit an existing registry key that is used when double-clicking the .jar file. The problem is that the data I'm trying to enter contains quotes, but I also need quotes to make it count as a string.

Example:

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 

When I run this in a script package, the cmd window displays "Error: too many command line options"

So, to make it simple. I want to add a registry key with "C: \ Program Files \ Java \ jre7 \ bin \ javaw.exe" -jar "% 1"% * as data, including quotes, and% 1 and% * exactly as they are does not translate to any actual statement or string.

EDIT:

A registry is usually added using this command line:

 ftype jarfile="C:\Program Files\Java\jre7\bin\javaw.exe" -jar "%1" %* 

it works fine on the command line, but just like the code below, when I used this in a script package, "% 1" and% * are not displayed.

+9
source share
5 answers

Use a backslash to escape inside 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 
+17
source

Percent literals must be doubled in a batch file: \"%%1\" %%*"

+11
source

As a complement to dbenham's answer, you should use back bounces and quotes for the path to the location!
(I mean, you should use "\"C:\Program Files..... instead of "C:\Program Files..... )

so this is the final answer for a typical percent sign & with the addition of a problem:

 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 

thanks dbenham!

+2
source

Another alternative is to use single quotes, some applications may read it correctly, for example:

 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 
+1
source

Many thanks. I struggled with this for 7 hours. This post saved me! Just as an example, I am attaching my example: this is in perl: my $ reg_cmd = "reg add \" HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ SQLDB \ "/ v ImagePath / t REG_EXPAND_SZ / d \" \\ "$ install_dir \ sybase \ bin64 \ db.exe \\ "- hv SQLtDB \" / f / reg: 64 ";

0
source

Source: https://habr.com/ru/post/909965/


All Articles