Reputation: 165
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
Upvotes: 0
Views: 3067
Reputation: 165
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();
Upvotes: 4
Reputation: 4030
I think you'll need to decode the LNK to get the actual EXE path/file.
See: Windows shortcut (.lnk) parser in Java?
Upvotes: 0