Search code examples
javaparameter-passinglnk

Open shortcut (.lnk) with parameter lines Java


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


Solution

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

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