如何找到Startup文件夹在Java中的位置?

时间:2010-12-30 21:28:38

标签: java windows startup-folder

在我的Java程序中,如何找到Startup文件夹在其他PC上的位置?我知道它在不同版本的Windows上有所不同。我只需要我的应用程序在Windows上工作。任何示例代码?

2 个答案:

答案 0 :(得分:1)

这应该有效:

System.getProperty("user.dir")

这里有一个关于系统属性的概述:

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

答案 1 :(得分:1)

使用ShellLink创建快捷方式非常简单。 https://github.com/BlackOverlord666/mslinks

行家:

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

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