0

In my java app i'm adding some values to registry through reg.exe but i can't seem to get double quotes working. My code looks like this:

rt.exec("REG ADD HKCU\\Software\\MyApp\\Settings /v myPath /t REG_SZ /d \"C:\\mydir\"");

As you can see i have already escaped the double quotes with \" but when i view the registry the added value has no double quotes. Any idea what's wrong?

justme_
  • 645
  • 2
  • 8
  • 11

4 Answers4

2

The cmd.exe shell is "helpfully" stripping quote characters for you. This has nothing to do with either Java or reg.exe.

This answer to a similar question may be helpful to you.

Also, you should look into using a ProcessBuilder instead of Runtime.exec().

Community
  • 1
  • 1
Daniel Pryden
  • 59,486
  • 16
  • 97
  • 135
0

In this case you should add additional quotes:

rt.exec("REG ADD HKCU\\Software\\MyApp\\Settings /v myPath /t REG_SZ /d "\"C:\\mydir\""");
antyrat
  • 27,479
  • 9
  • 75
  • 76
Igor Shenderchuk
  • 698
  • 4
  • 12
0

You can try creating a temporary file with the registry value you want and add it that way. REG IMPORT will do the job for you and you don't have to worry about quotes except for the case where there is a space in the file name.

Archimedes Trajano
  • 35,625
  • 19
  • 175
  • 265
0

The double quotes should NOT appear in registry entry. The double quotes are eaten by the commadn line processing.

Richard Schneider
  • 34,944
  • 9
  • 57
  • 73