0

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

michael
  • 165
  • 1
  • 2
  • 11
  • According to http://stackoverflow.com/questions/4749660/execute-file-lnk-in-java it does in fact work. – Robin Green Nov 10 '13 at 22:27
  • CreateProcess error=193, %1 is not a valid Win32 application at java.lang.ProcessBuilder.start(Unknown Source) – michael Nov 10 '13 at 22:29

2 Answers2

4

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();
michael
  • 165
  • 1
  • 2
  • 11
0

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

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

Community
  • 1
  • 1
Glenn Lane
  • 3,892
  • 17
  • 31
  • Exactly what I was looking for, thank you very much. ProcessBuilder pb = new ProcessBuilder("cmd", "/c", "C:\\path\\shortcut.lnk", "-n", "100"); Process process = pb.start(); – michael Nov 10 '13 at 22:36