0

I'm following this trying to put my program at startup on windows systems after login: Starting a Java application at startup

But it doesn't work. My code:

static final String REG_ADD_CMD = "reg add \"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\" /v \"{0}\" /d \"{1}\" /t REG_EXPAND_SZ";

private void exec(String[] args) throws Exception
{
    if (args.length != 2)
        throw new IllegalArgumentException("\n\nUsage: java SetEnv {key} {value}\n\n");

    String key = args[0];
    String value = args[1];

    String cmdLine = MessageFormat.format(REG_ADD_CMD, new Object[] { key, value });


    System.out.println("cmd line: "+cmdLine);

    Runtime.getRuntime().exec(cmdLine);
}

@Override
public void autostartupInstalation() {
    try {
        String[] args = {"javaLL" , "javaw -Xmx200m -jar "+ super.installPathFile};
        exec(args);

    } catch (Exception ex) {
        MainClass.getMainClass(InstallerWindows.class.getName()).log(Level.SEVERE, null, ex);
 }

I'm using windows 7, and executed under a cmd or admin cmd. What could be the problem?

It doesn't show any error code or exception. Also showing my process, when i finalize the program, starts a proces called reg.exe that i don't know what is. For every instance of the program that I finalize start one of this proces.

Community
  • 1
  • 1
selan
  • 956
  • 3
  • 11
  • 27
  • 2
    "Doesn't work" does not describe a specific problem. Does it throw an exception? Does it print any message? Does it write the key to a different place in the registry? ... – Andy Turner Dec 02 '15 at 13:59
  • Possible duplicate of [read/write to Windows Registry using Java](http://stackoverflow.com/questions/62289/read-write-to-windows-registry-using-java) – dguay Dec 02 '15 at 13:59
  • You might be better using a Windows service -> http://commons.apache.org/proper/commons-daemon/jsvc.html – Sebastian Dec 02 '15 at 14:01
  • If it *doesn't work* as you say then you should get an **error** somewhere, these **errors** help us find and fix things that otherwise we cannot, please post the error you're encountering so that we *can* help you ;) – SidOfc Dec 02 '15 at 14:03
  • Yes sorry I was just solving this. It doesn't show any error and the key aren't writtted. It could be because I have the regedit.exe in execution at same time? – selan Dec 02 '15 at 14:08
  • hey @dguay , when I use the class of the other article, the method readValues return me other values that I see in the regedit... – selan Dec 02 '15 at 14:51

0 Answers0