Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find where the Startup folder is with Java?

In my Java program how can I find out where the Startup folder is on uers' PCs ? I know it's different on different versions of Windows. I only need my app to work on Windows. Any sample code ?

like image 830
Frank Avatar asked Dec 18 '25 04:12

Frank


2 Answers

With ShellLink creating shortcuts is very simple. https://github.com/BlackOverlord666/mslinks

Maven:

<dependency>
  <groupId>com.github.vatbub</groupId>
  <artifactId>mslinks</artifactId>
  <version>1.0.5</version>
</dependency>

Refer answer by https://stackoverflow.com/a/38952899/4697928

private final String STARTUP_PATH = "/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup";

private void checkAutoStartPresent() {
    File file = new File(System.getProperty("user.home") + STARTUP_PATH + "/YourShortcutFileName.lnk");
    if (!file.exists()) { // shortcut not found
        try {
            ShellLink.createLink("/YourTargetProgramPath.exe", file.getAbsolutePath());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
like image 120
Abishek Stephen Avatar answered Dec 19 '25 18:12

Abishek Stephen


This should work:

System.getProperty("user.dir")

here you have an overviwe about system properties:

http://download.oracle.com/javase/tutorial/essential/environment/sysprop.html

like image 36
RoflcoptrException Avatar answered Dec 19 '25 17:12

RoflcoptrException



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!