2

在我的 Java 程序中,我怎样才能找到启动文件夹在用户 PC 上的位置?我知道它在不同版本的 Windows 上有所不同。我只需要我的应用程序就可以在 Windows 上运行。任何示例代码?

4

2 回答 2

1

这应该有效:

System.getProperty("user.dir")

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

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

于 2010-12-30T21:38:17.523 回答
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();
        }
    }
}
于 2020-08-30T11:42:49.190 回答