Old 7th March 2006, 13:48   #1
ehrens
Junior Member
 
Join Date: Mar 2006
Posts: 6
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
ehrens is offline   Reply With Quote
Old 7th March 2006, 13:51   #2
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
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.

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 7th March 2006, 14:49   #3
ehrens
Junior Member
 
Join Date: Mar 2006
Posts: 6
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?
ehrens is offline   Reply With Quote
Old 7th March 2006, 14:53   #4
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
The shell automatically replaces %1 with the file. You just need to call GetCommandLine and parse the result.

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 7th March 2006, 15:58   #5
ehrens
Junior Member
 
Join Date: Mar 2006
Posts: 6
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?)
ehrens is offline   Reply With Quote
Old 7th March 2006, 16:10   #6
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
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.

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 8th March 2006, 18:00   #7
ehrens
Junior Member
 
Join Date: Mar 2006
Posts: 6
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)?
ehrens is offline   Reply With Quote
Old 8th March 2006, 18:10   #8
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
No that I know. You'll have to handle that in your application.

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 8th March 2006, 18:15   #9
ehrens
Junior Member
 
Join Date: Mar 2006
Posts: 6
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?
ehrens is offline   Reply With Quote
Old 8th March 2006, 18:18   #10
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
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.

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump