2

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

4
  • Why not simply put the jar file into startup folder? Commented Sep 2, 2015 at 5:43
  • I can, but the receiver demanded for not to have dependency on system. Try to code for startup also. Commented Sep 2, 2015 at 5:45
  • Make sure you have set the correct file separator for WIndows "\" Commented Sep 2, 2015 at 5:49
  • I have set them correctly. I have manually checked it in regedit Commented Sep 2, 2015 at 5:51

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

2 Comments

I mentioned in the above comments that but the receiver demanded for not to have dependency on system
It is not a dependency of the system. You can distribute the .bat file with your program.
1

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.

1 Comment

Yeah, javaw is better.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.