Harshit
Harshit

Reputation: 5157

Java add program to startup

I have used jna library to write to windows registry to add my program to startup. When I saw in the registry, it got added fine. I used the code

Advapi32Util.registrySetStringValue(WinReg.HKEY_LOCAL_MACHINE,
    "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", FILE_NAME, FILENAME_FILEPATH);

The save data in registry is like

key - program.jar
value - PATH/program.jar

If I double click the program.jar file, it gets executed fine, but why it is not executing at startup ?

Thanks

Upvotes: 2

Views: 1396

Answers (2)

hinneLinks
hinneLinks

Reputation: 3736

When you double click on a Jar-File in Windows, Windows starts Java and pass that Jar-File as an argument to it, just like you double click .docx Files - Windows starts Word and pass that File as an argument to it.

With that registry command you have to do the same - start Java and pass the jar-File as an argument to it. Try using this command in your registry (you can try it on the command line first):

java -jar path/to/jarfile.jar

Maybe you'll see a console with java, if thats the case, you can use javaw instead.

Upvotes: 1

Amila
Amila

Reputation: 5213

Try writing a .bat file to execute your program (java -jar) and set the .bat file path in registry.

Upvotes: 3

Related Questions