I'm trying to use Java to create a start up registry key and I'm getting a really weird result. On some OS's such as XP the command works flawlessly. However, on Windows 7 it only creates the key if you run the compiled jar or classes, and not from an applet on a web page. Additionally on Windows 8, the command does not work at all. I've tried debugging this, and it seems that the REG command is executing successfully. If I run the command manually from command prompt, it creates the keys, with the same output as when it's ran from inside the program. Heres an example of the code:
public static int regadd(String key, String name, String val) throws IOException, InterruptedException {
ProcessBuilder pb = new ProcessBuilder(new String[]{"REG", "ADD", key, "/v", name, "/d", val, "/f"});
pb.redirectOutput(new File(PathManager.getDirectory(), "log0.txt"));
int i = pb.start().waitFor();
Logger.log("ADD: " + i);
return i;
}
In log0.txt it prints this:
The operation completed successfully.
Additionally, the "result" of the program prints
ADD: 0
So at this point, I am at a loss of what could be the problem. I am aware of the other dicey ways to add to the registry, but I would like to keep my code compatible with all VM distributions. Is there a way to accomplish this or fix the exiting method?