Launch Java application at startup

I have a Java application.

The app has a parameter that determines whether the app is launched at startup.

I currently have this by putting / removing a shortcut in the StartUp items folder.

However, I'm wondering if there is a better way to deal with this behavior.

EDIT

Yes, it's Windows. Sorry I didn't clear this sooner.

The app has a user interface where the user can launch actions, and the app periodically runs multiple tasks in the background while it is running.

@Peter, how can I change the registry with code from within the application? Is this approach compatible with all versions of Windows?

+1


source to share


3 answers


Below is a small snippet of an example of how this can be done from within your application.

static final String REG_ADD_CMD = "cmd /c 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 });

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

      

I'm sure this will work with all versions of Windows as they all use the same Startup \ Run registry entry.



Hope it helps! :)

Credit

+2


source


On Windows, I used an open Java Service Wrapper to make our application as a service window that you can set to be automatic on startup.



What you need to do is to download latest wrapper.exe and create wrapper.config file put all the configuration like Main class any VM arument other parameters in defined standards and create a window service by this exe

0


source


Use Registry to run your program at startup and then it will show up in the list given by msconfig

commnd via Run

. Use this registry path

HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

0


source







All Articles