开发者

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 u开发者_StackOverflow社区ers' PCs ? I know it's different on different versions of Windows. I only need my app to work on Windows. Any sample code ?


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


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();
        }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜