2
我的應用程序在用戶創建.bat
文件Startup
目錄能夠自動運行時,在用戶登錄Java中創建批處理文件和逃生空間
我這是在當前如何創建.bat
:
File startupFile=getStartupFile();
PrintWriter out=new PrintWriter(new FileWriter(startupFile));
out.println("@echo off");
out.println("start " + System.getProperty("user.dir") + fileSeparator +"MyApp.exe");
out.println("exit");
out.close();
}
BTW:startupFile
只是位置到Startup
目錄
的問題似乎是,有時System.getProperty("user.dir")
包含在路徑中有空格。例如,第二條線可以是:
start C:\Program Files (x86)\MyApp\MyApp.exe
當它試圖找到運行應用程序這打破了.bat
文件。
任何想法如何使.bat
知道在哪裏可以找到應用程序?無論它在哪裏安裝?
這隻能打開一個空cmd窗口,couldent得到它的工作 – Alosyius
@Alosyius什麼是你'MyApp.exe'做? –
它是一個java可執行文件,與launch4j打包到一個.exe – Alosyius