"file.myext" is not a valid Win32 application
I have written a registry that creates .myext
.
Double-clicking on my file.myext
refers to my executable file (converted from a batch file that opens a .jar
) which then opens my notepad application.
The registry
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\.myext]
@="myext"
[HKEY_CLASSES_ROOT\.myext\ShellNew]
[HKEY_CLASSES_ROOT\myext]
@=".myext file"
"EditFlags"=dword:00000000
"BrowserFlags"=dword:00000008
[HKEY_CLASSES_ROOT\myext\DefaultIcon]
@="C:\\...\\icon.ico, 0"
[HKEY_CLASSES_ROOT\myext\shell]
[HKEY_CLASSES_ROOT\myext\shell\Open]
[HKEY_CLASSES_ROOT\myext\shell\Open\command]
@="C:\\...\\run.exe %1"
My executable (run.exe) that was converted from a batch
start /min "C:\...\javaw.exe -jar" "C:\...\mjar.jar"
Problem?
I don't know why I am receiving that error message. Perhaps it was this conversion application that's causing some problems.
SUGGESTIONS
Here is what I have done after everyone's suggestions. I am able to successfully open my text editor (with any one of the following suggestions) after clicking on a document, but no text appears in theJTextPane
. If I choose to open the document in Windows Notepad, all the text shows up.
P.S. I am not using DDE and I no longer receive the error message: "file.myext" is not a valid Win32 application
.
BATCH FILE SUGGESTIONS
start "Mike's Text Editor" /min "C:\...\javaw.exe" -jar "C:\...\mjar.jar"
start /min "C:\...\javaw.exe -jar" "C:\...\mjar.jar" "%1"
REGISTRY SUGGESTION
[HKEY_CLASSES_ROOT\myext\shell\open\command]
@="\"C:\\...\\run.exe\" \"%1\""
Solution 1:
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 yourfile.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 yourrun.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.
Solution 2:
Your problem is how you use the start
command.
By putting the first parameter into ""
you assign that as the title of the window for the started program. Then you pass %1
into it (which you noted in the comments of your question). %1
is the filename of the .myext
file you clicked. So that is the file start
tries to execute.
Which results in the error you're seeing.
So, to solve it, just use start
like this:
start "something" /min "C:\...\javaw.exe" -jar "C:\...\mjar.jar"
The first parameter passed to start
which is enclosed in ""
is expected to be the title of the resulting (console) window.
The second parameter (that doesn't start with a /
) is expected to be the executable to start. If the path to it contains spaces, it needs to be enclosed in ""
. Otherwise, they're optional.
The third and all following parameters will be passed to the executable.
So those don't need to be enclosed in ""
separately. But you do need to enclose paths (that contain spaces) in those parameters in ""
so the executable can parse them properly when started.