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.