New Answer
This is the bare minimum you need to associate correctly. I found this out by trying my own tip number 4 below (You can find out how Windows does this for you...).
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\.myext]
@="myext"
[HKEY_CLASSES_ROOT\myext]
@=".myext file"
[HKEY_CLASSES_ROOT\myext\shell]
[HKEY_CLASSES_ROOT\myext\shell\open]
[HKEY_CLASSES_ROOT\myext\shell\open\command]
@="\"C:\\...\\run.exe\" \"%1\""
You can add DefaultIcon and other things as necessary, but without DefaultIcon, Windows will simply use the icon in run.exe (if it has one. You can add one in the Batch To Exe Converter when you create the run.exe).
Importance of %1 and quote marks
The reason why you need to put a %1 there is to pass the path and name of the associated file (file.myext) into the program run.exe. Without passing this in, your association is pointless as it's functioning simply as a shortcut. This is unnecessary as you can simply create a normal shortcut to run.exe to serve the same purpose.
Your batch file should also have a %1 somewhere inside so that the path and name of the associated file (file.myext) is used inside the batch file (presumably to pass it to your mjar.jar which will do something with the file). Otherwise, no matter which associated file you double-click on, you'll always get the same result from your Java program. This is once again pointless as you can simply have a shortcut to the batch file to serve the same purpose.
It is also important to enclose the %1 in quotation marks, as file paths can contain spaces, and without the quotes (") these spaces can split the path into two or more arguments (when the entire path is intended to be regarded as one argument).
Example batch file
Here is the batch file I converted to exe for testing. It simply displays whatever the value of %1 is.
@echo %1
@pause
Your batch file could be as shown below (so that mjar.jar can get the path and name of the file you're double-clicking on):
start /min "C:\...\javaw.exe -jar" "C:\...\mjar.jar" "%1"
I associated the exe file with .myext extension (using method in my tip 4) and then checked registry to create the above .reg file. When I double-click on a file with .myext extension, a command window opens, displaying (echo command) the path and name of the file I double-clicked (this is how my test batch file is using the associated file).
Java program
(This is a summary of the full chat discussion that eventually solved your problem.) Your Java program contained in mjar.jar must be prepared to accept the incoming argument and use it. Your intention is for your program to automatically open the file referred by the incoming argument and display its contents. Hence the main method should be something like this:
public static void main (String[] args) {
if (args.length >= 1) {
openFile(args[0]);
}
}
The openFile method is a method that opens the file by the name passed into it. The if statement ensures that args[0] is only read when there is such an argument (avoiding ArrayIndexOutOfBoundsException). Only the first argument args[0] is used in the above code; all other arguments (args[1], args[2], etc.) are ignored. The openFile method would be something like this (descriptors and return types not included):
openFile(String filename) {
// code here to open the file referred by "filename" variable,
// read its contents and display it on the GUI
// or use it in the program as intended
}
If your program has an Open command built into its GUI, after the user chooses a file with this command, your application can make use of the same openFile method above to open the chosen file and display its contents.
Previous Answer
I do not have a definitive answer to your problem yet, but here are some tips to get you started:
Have you tried adding quotes? Like this: @="\"C:\\...\\run.exe\" \"%1\""
In the registry, the (Default) value will show up like this: "C:\...\run.exe" "%1"
Read Microsoft's official MSDN doc about File Type Association. You will also have to read up about Programmatic Identifiers (linked in the first para of that document).
Try associating your .myext file type with Notepad first. Find out how Notepad is associated to .txt files and follow the example. If done correctly, Notepad should open your file.myext file.
You can find out how Windows does this for you. Right-click file.myext, click Open with > Choose default program...^ and Browse to find your run.exe file. Associate and open, then investigate the Windows registry to find out how Windows stored your manual association. You can then simply export the file type and the programmatic identifier to reg files.
^ If file.myext is unassociated, click Open > Select a program from a list of installed programs.
PS1: Apparently, you must have double backslash in .reg files.
PS2: It's better to directly edit stuff in registry, test the effects, then export the keys to .reg files and combine them to a single file, rather than create a .reg file yourself.