[英]How to find where the Startup folder is with Java?
在我的 Java 程序中,如何找到用戶 PC 上的 Startup 文件夾? 我知道它在不同版本的 Windows 上有所不同。 我只需要我的應用程序即可在 Windows 上運行。 任何示例代碼?
這應該有效:
System.getProperty("user.dir")
在這里,您對系統屬性有一個概述:
http://download.oracle.com/javase/tutorial/essential/environment/sysprop.html
使用 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();
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.