Archive: Know which app was fired?


Know which app was fired?
I'm posting this because I received a good response to my previous post and really have no idea where to post this or how to phrase it. I have the installer working beautifully and it makes my file associations in the registry. So, here's my question...

if I have two files...say, like emails...and one is stuff.abc and the other is things.abc... I click on one. The association launches my ABCReader. Now, how do I know which file was clicked on so that my Reader can bring that file up in the viewer?

Thanks for any help either on the question or insight as to where I should ask this question.

Aaron


Usually, when you associate file types, you set the command line to be something like "C:\myprog\prog.exe %1". That %1 is replaced with the path to the opened file. The command line can be read in your program using GetCommandLine or argc and argv in main if it's a command line program.


Thanks! Do you have to do anything to specify the path then of the file that is being opened or does the OS handle that for you and just put it in there for the %1?


The shell automatically replaces %1 with the file. You just need to call GetCommandLine and parse the result.


getCommandLine... Is this a Java call? If so, do you know what library I would need? I can't seem to find it in the basic jdk stuff.

Also, I have two ways that I need to support things... 1 is by launching an .exe with the file and 2 would be to launch a batch script. In the batch script, how would I snag the value of the %1 without using the getCommandLine (or have I gone off the deep end?)


It's a Windows API. I've added a link to it in the first reply. In Java, the arguments passed on the command line are passed as parameters to your 'main' function.

In a batch file, use %1 to get the first command line parameter, %2 to get the second, etc.


Very cool.... I have it passing in the filename and now have 1 last question... It's running the exe local to the directory of the file that I doubleclicked (so, if on the desktop, app is launched from Docs and Settings but if in c:\app\export, then the app is launched relative to that dir). Is there a way to specify, regardless of where the app was launched, where it should be run relative to the directory structure that was installed (ie, always run relative to the app\bin directory that installed)?


No that I know. You'll have to handle that in your application.


Thanks so much for the help and for the quick responses... Last question for a while.... if I click on 3 files, it opens 3 instances of my app. Is there a way to only open 1 instance and pass in all 3 filenames?


There's probably some value you can write in the association registry key that'd do that. MSDN or an existing example could help there. If not, you can always have your application check if it's already running.