문제

I'd like to start a shortcut with parameter-lines How could I execute this shortcut with parameters in Java? (As this doesn't work with ProcessBuilder I'm stuck once again...)

"C:/Program Files/MyPrograms/MyShortcut.lnk" -s 3 -n 100 (what ever these parameter lines mean now)

I'm sucessfully able to launch my shortcut, without parameters.

code:

String directoryFile = "C:/Program Files/MyPrograms/MyShortcut.lnk"

Desktop.getDesktop().open(new File(directoryFile));

What I want:

String directoryFile = "C:/Program Files/MyPrograms/MyShortcut.lnk"

Desktop.getDesktop().open(new File(directoryFile)+"-s 3 -n 100");

This does work, but only for .exe files; I'd need to open a .lnk(win shortcut) with parameters

Process p = new ProcessBuilder("C:/Program Files/MyPrograms/MyFile.exe",
                                          "-n", "100")
                                      .start();

Thanks

도움이 되었습니까?

해결책 2

I think you'll need to decode the LNK to get the actual EXE path/file.

See: Windows shortcut (.lnk) parser in Java?

다른 팁

If someone is looking for the same thing, this worked like a charm! (thanks to 'Glenn Lane' for linking me)

ProcessBuilder pb = new ProcessBuilder("cmd", "/c", "C:\\path\\shortcut.lnk", "-n", "100"); Process process = pb.start();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top