-3

I would like to quick modify a simple .bat to insert an input file of choice in the executing string. Namely, the simple .bat string is:

java -cp myapp.jar infile

Wonder if there is a smart way to send the infile from Win explorer (or other file manager) to such string, without doing it via cmd-line-typing everytime? Besides, java might need additional controls, so in a properly prepared .bat the only variable will be the infile-name at end of string. Thanks for a thought in advance!

Leo
  • 11
  • 1
  • 2
    Well let's see your attempt at a bat file – barlop Feb 09 '21 at 02:54
  • at a minimum you are looking for https://ss64.com/nt/syntax-args.html – Frank Thomas Feb 09 '21 at 05:36
  • See [here](https://www.howtogeek.com/howto/windows/add-the-command-prompt-to-the-windows-explorer-right-click-menu/) and [here](https://superuser.com/questions/136838/which-special-variables-are-available-when-writing-a-shell-command-for-a-context) – Daniel Feb 09 '21 at 07:03
  • Actually, this one talks about how to do it for file context menu which is what you want - https://stackoverflow.com/questions/2123762/add-menu-item-to-windows-context-menu-only-for-specific-filetype – Daniel Feb 09 '21 at 07:14

1 Answers1

1

Here is the ultimate solution (thanks to all contributors): creating an exec string with the infile-name variable under the needed file association's Command key in the registry. Create the association and descendent keys if necessary.

Windows Registry Editor Version 5.00

HKEY_CLASSES_ROOT\SystemFileAssociations\.myfiletype\shell\subtitle
@=Open with Myapp...

HKEY_CLASSES_ROOT\SystemFileAssociations\.myfiletype\shell\subtitle\command
@="C:\sys_path_to\javaw.exe" -cp "C:\path_to\Myapp.jar" org.appropriate.java.class %1

where %1 is the variable for infile-name for .myfiletype passed via shell context menue (specified in subtitle key). This fully takes over the initially bat-written string. Needed to replace java.exe with javaw.exe to run it shell-less.

Works just neatly, awesome.

Leo
  • 11
  • 1