Adding a registry key in windows with quotes needed in the data using a batch script

后端 未结 4 623
夕颜
夕颜 2021-02-04 13:40

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 tryi

相关标签:
4条回答
  • 2021-02-04 14:18

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

    0 讨论(0)
  • 2021-02-04 14:19

    Another alternative is to use single quotes, some applications can read it properly, 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
    
    0 讨论(0)
  • 2021-02-04 14:20

    as an addition to dbenham's answer, you should use backslaches and quotes for location path !!
    (i mean, you should use "\"C:\Program Files..... instead of "C:\Program Files..... )

    so this is the final answer for typical percent sign & adding 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!

    0 讨论(0)
  • 2021-02-04 14:31

    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
    
    0 讨论(0)
提交回复
热议问题