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



@=".myext file"

@="C:\\...\\icon.ico, 0"



@="C:\\...\\run.exe %1"

My executable (run.exe) that was converted from a batch

start /min "C:\...\javaw.exe -jar" "C:\...\mjar.jar"


I don't know why I am receiving that error message. Perhaps it was this conversion application that's causing some problems.


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 the JTextPane. 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.


start "Mike's Text Editor" /min "C:\...\javaw.exe" -jar "C:\...\mjar.jar"

start /min "C:\...\javaw.exe -jar" "C:\...\mjar.jar" "%1"


@="\"C:\\...\\run.exe\" \"%1\""
  • Do you need it to be an executable instead of a batch file? Did you try running the executable on its own? Have you tried using the batch file in the command key to see if that works? – Synetech Feb 15 '12 at 20:54
  • @Synetech Yes. The executable works on its own and it works using the batch file in the command key. The error message pops up when I double click on my file that was saved using my Java application. – Rob Feb 15 '12 at 21:14
  • 1
    Forgot to ask this, how does your run.exe use the file.myext or whatever file is associated with it? I don't find any %1 in your batch script, which is necessary to pass in arguments (file.myext in this case). – ADTC Feb 19 '12 at 7:40
  • 1
    So does start "" /min "C:\...\javaw.exe" -jar "C:\...\mjar.jar" %1 work? It should. – Synetech Feb 23 '12 at 3:21
  • 1
    To be honest, it’s not really clear what’s going on. What exactly are the .myext files and what exactly is mjar.jar? Is mjar.jar a tet editor and .myext files are text files? Are you trying to create a new text filetype that is opened with a Java text editor? – Synetech Feb 23 '12 at 3:23

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


@=".myext file"



@="\"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

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) {

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.

| improve this answer | |
  • Excellent answer. I tried adding quotes in numerous places (just like your suggestion) but it never worked properly. Thank you very much for the link! I've been reading up on it and it seems quite helpful. – Rob Feb 19 '12 at 14:49
  • @Mike I have updated the answer. Please check for new answer above previous one. – ADTC Feb 19 '12 at 16:34
  • Thank you for the explanation on why it is important to have %1, I had a hunch that it was used for referencing or passing a variable. At any rate, I wrote my registry with your suggestions and it worked flawlessly. The one issue that persists is the fact that no text shows up in my notepad application when I double click on a .myext file. When I select "Open with" and choose Notepad, the text shows up. I'm starting to think this is an issue with my code... – Rob Feb 19 '12 at 20:17
  • > The one issue that persists is the fact that no text shows up in my notepad application when I double click on a .myext file. When I select "Open with" and choose Notepad, the text shows up. I'm starting to think this is an issue with my code. @Mike, you said it works when you do it manually, so that should not be it. The problem remains that the (correct) file is not being opened. Try using "%L" instead of %1. – Synetech Feb 19 '12 at 22:42
  • @Synetech apologies, there is a %L syntax but it seems unnecessary (Doesn't Windows already pass in long file names with %1? Short 8.3 names are already outdated. You just have to ensure you have surrounding quotes.). @Mike Have you tried associating .myext to Windows Notepad? Does the file then open correctly? If yes, then the problem is in your Java code. May I ask, however, what exactly does your mjar.jar do with the file that is passed in to it using the "%1"? – ADTC Feb 20 '12 at 10:06

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.

| improve this answer | |
  • 1
    +1, sounds very likely. This has bitten me at least twice, and still I didn't spot it in the OP... – Jonas Heidelberg Feb 22 '12 at 19:26
  • I tried your suggestion and I received an error message: Windows cannot find 'C:\...\javaw.exe -jar'. Make sure you typed the name correctly, and then try again. Just to make sure, "something" is the title of the window, right? – Rob Feb 22 '12 at 20:55
  • Yes, "something" the title of the window. I think there might be an incorrect placed " in my answer. Will fix it right now. – Der Hochstapler Feb 22 '12 at 21:06
  • The application opens up properly but the text area is still blank. P.S. the batch file does not use DDE. – Rob Feb 22 '12 at 23:05
  • 1
    Please put the exact contents of your batch file in your question. I also don't know about the text area. Please put all relevant information from comments in your question. – Der Hochstapler Feb 22 '12 at 23:09


You have your command set to this:

@="C:\\...\\run.exe %1"

Spaces are delimiters and used to separate different parts of a command and its arguments. If you had no spaces in the filenames, then it would work:

C:\Foobar\run.exe c:\test.myext

If have spaces in the file (or its path) being passed, the program may or may work correctly depending on how it interprets its arguments:

C:\Foobar\run.exe C:\My Docs\test.myext /switch

Is C:\My argument one and Docs\test.myext argument two? Are all the arguments a single string? Is there some special interpretation?

If you have spaces in your program (or its path), then Windows will not be able to identify which parts are the path and/or filename, and which parts are other arguments:

C:\Program Files\Foobar\run.exe C:\test.myext

Windows tries to run the file C:\Program and pass Files\Foobar\run.exe and C:\test.myext as arguments to it.

As you can see, this is clearly not a valid filename. If you entered it in the Run dialog, you would get the same cannot find/not valid app error message.


What you need to do is to wrap file/pathnames in quotation marks to clarify that they are a single unit. This is usually straight-forward, but not always.

In your case, it should be pretty easy. If you are entering it directly in Regedit, use this (replacing the paths as necessary). Navigate to HKCR\myext\shell\open\command and edit the default item and set it to:

"C:\Program Files\Foobar\run.exe" "%1"

If you are putting it in a .REG file, use this:

@="\"C:\\Program Files\\Foobar\\run.exe\" \"%1\""

Note how the slashes and quotes are escaped (with a slash), but both the program and the file argument are quoted. This is good regardless of whether there are spaces in the path/filename; it’s just safer.

Also, you can replace the %1 with %L to pass the fully-qualified path to the file should your program require it.

| improve this answer | |
  • I want to apologize for not getting back to you sooner but I would also like to thank you for the very knowledgeable information. I have updated all of my code and compared it with ADTC and your suggestions, but I continue to have problems with showing the text in my application (no problems with opening the file with Windows Notepad). – Rob Feb 22 '12 at 0:03
  • It narrows the problem down to the compiled EXE… sort of. From your responses it seems that you can successfully use an executable like Notepad and successfully use your raw batch file. The problem only arises when you use the compiled batch file. (You did say that the compiled batch file runs correctly when you manually run it right?) That makes it quite confusing. If the executable is not corrupt and does indeed work when run manually, and the context-menu item you created works with other programs, then why would the compiled batch file not work from the menu? It doesn’t use DDE does it? – Synetech Feb 22 '12 at 1:55
  • @Synetech //why would the compiled batch file not work from the menu? It doesn’t use DDE does it?// In my test, this part worked absolutely fine. I could execute the context-menu item and the compiled EXE file will correctly get and display the file name. (I'm pretty sure it would display the file contents as well if I had included a more command.) Until @Mike confirms that his .jar file is able to correctly process the incoming file, we can't narrow down the problem source properly. (He has not done that in his comment here and has not answered my question yet!) – ADTC Feb 22 '12 at 5:00
  • @Synetech and Mike Please join the chat room I created for this topic. Thanks! This discussion using comments here and there is getting very long and disorganized, and the wait times are very tiring. – ADTC Feb 22 '12 at 5:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.