Starting a Java application at startup

前端 未结 3 1058
别跟我提以往
别跟我提以往 2020-12-18 16:03

I have a Java application.

The application has a setting that decides whether or not the application starts at startup.

Currently, I have it this by placing

相关标签:
3条回答
  • 2020-12-18 16:55

    Use the Registry to start your program at the startup and then it will be shown in the list provided by msconfig commnd through Run. Use this registry path

    HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

    0 讨论(0)
  • 2020-12-18 16:57

    On Windows I have used open source Java Service Wrapper to make our application as window service which you can setup automatic at 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 讨论(0)
  • 2020-12-18 17:05

    Below is a small example snippet of how it can be done from inside 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 pretty sure this will work with all versions of Windows since they all use the same Startup\Run registry entry.

    Hope that helps! :)

    Credit

    0 讨论(0)
提交回复
热议问题