1

I'm trying to make a Windows' shell extension to add a program shortcut in the context menu of a certain file type. I've got it working for a random application, but the problem comes when I try to make it execute a java program.

I'm putting this as command:

java -jar "Path\To\MyJar.jar" %1

But when I click on the context menu item, it opens the "Open with" window. It also happens using java "Path\To\MyClass.class" %1.

Aren't those types of commands a valid input for the command key? Is there any other alternative? (besides of using an .exe wrapper like with Launch4j).

Thanks!

EDIT: Actually, using this as command:

"myBat.bat" %1

where "myBat" only executes the java command given before, is able to execute the program. But unfortunately, %1 only passes the path until it finds a space, so this alternative can't be used.

eric.m
  • 1,577
  • 10
  • 20
  • 1
    You need to put %1 under quotation marks ("%1") to prevent this. – Syberdoor Sep 02 '15 at 06:03
  • Thanks, that works for the bat, but is it possible to directly put the java command? – eric.m Sep 02 '15 at 10:34
  • I don't know a reason why it shouldn't. You need quotationmarks for java as well probably, but other than that. Did I understand this right though you want the file to be opened with your jar application, correct? You don't want your jar to be opened with java? Only thing I can see wrong with that other than the quatation mark is the path to java.exe – Syberdoor Sep 02 '15 at 11:03
  • Okay, using the java.exe path works fine. But can't we just use the word `java` ? It works fine in the cmd. – eric.m Sep 02 '15 at 11:58
  • the cmd uses two things if you use just "java" the environment variables path and pathext. Path contains all the default paths of where to search for an exe, pathext all extensions to add to a file if it has none. So if you use "java" cmd basically searches all the combinations of the entries for these two to find something to execute until it finds java.exe in it's path. If this does not work in the registry then I would assume the path or pathext variables (or both) are not searched by the shellexecutor.. I cannot say for sure though, my knowledge of windows is not that deep sadly. – Syberdoor Sep 02 '15 at 13:10
  • Okay, thanks. I will probably run it through java temprorarily, until I create it a .exe. – eric.m Sep 02 '15 at 13:13
  • One thing that just came to my mind... are you hesitant to use the path to the java.exe because it includes the version number and you are afraid if you upgrade java you have to redo that? If so I think all the current java versions copy some dummy java.exe to c:\windows or c:\windows\system32 or something that then redirects to the real one. You can try if that works. – Syberdoor Sep 03 '15 at 05:40

0 Answers0