Archive: Need help with GetParameters function


Need help with GetParameters function
I currently have code that will give me the name of the batch file calling the NSIS executable (I must use a batch file for this application). The program that calls the batch file is another software that passes some data to our app by means of the batch and NSIS file combination.
Here is my current batch file code:

copy %1 mydata.dat
myapp.exe %0

As I mentioned above, I can already get the name of the batch file with the %0 parameter. What I would also like to do is to pass it the data with the %1 parameter so my batch file should just be something like:
myapp.exe %0 %1
The problem is I cannot figure out how to get %1 so I can copy it into a file/variable. How do I read the second parameter?

Re: Need help with GetParameters function
Put quotes around the parameters, so you will know when the second one starts.


I added quotes around the parameters so my batch file now looks like:

myapp.exe "%0" "%1"

I also added the following two things right before closing the GetParameters Function code:
* A message box to show me the values of $0, $1 and $2
( This is the code: MessageBox MB_OK "0=$0$\n1=$1$\n2=$2" )
* StrCpy $1 c:\mydata.dat

The values of $0, $1 and $2 come up blank and the data being transferred doesn't get copied into c:\mydata.dat


I forgot to mention that I am using 1.98


You need to write some code to separate these parameters. The StrCpy instruction does not write stuff to a file, it just copies a variable.

Can you post the other code?


$0, $1 and $2 are not the equivalent of %0, %1 and %2... You have to call the GetParameters function, then Pop to get its result and parse it. If you used myapp.exe "%0" "%1" to call the installer the string popped will be "%0" "%1" (%0 and %1 of course replaced by their real values...). You will then have to seperate this string to two strings by searching for the quotes and using StrCpy starting position parameter and number of characters to copy parameter.


Using the function GetNextParm, this should do the trick:

Push $CMDLINE
Call GetNextParm
Pop $0 ; name of installer
Call GetNextParm
Pop $1 ; first parameter
Call GetNextParm
Pop $2 ; second parameter
Pop $9 ; remaining parameters (not required - just keeping the stack tidy)

Attached is my NSIS script and batch file zipped up.

I will try to figure out Kichik's suggestion of "You will then have to seperate this string to two strings by searching for the quotes and using StrCpy starting position parameter and number of characters to copy parameter."

Thank you


Using GetNextParm will actually be easier :)


Thanks for the help, but I am still having problems figuring out how to implement the "GetNextParm" function in my code. I added the "GetNextParm" function as posted by eccles and called it from the .OnInit function (after "Call GetParameters"), but now I am getting a stack fault error when the exe is executed. What am I doing wrong?


You have an example of usage in the URL eccles gave you. You don't need to call GetParameters if you use GetNextParm...


GetNextParam should be using $R0..$R9 and not $0..$9. Using $9 around the start menu functionality in Modern UI wipes out the Start Menu folder.


Where did you find GetNextParm? The links above are dead.


That's a good question, I think I found it in included example piece of code posted somewhere on this board, but I can't remember where.


I still have the backups of that clantpa site. Does anyone want me to fish out the stuff that those dead links used to refer to?


I'll be happy to polish it if I'll get a copy of it ;)


clantpa.co.uk backup files
Here it is.

Also for anyone interested (you're pretty mad if you try this) I've made the backups accessible by ftp (ftp://nsis:nsis@sunjammer.serveftp.net). The reason I've done this is that I have very little time to go through them and yet there is potentially still useful information in there.


Hmm forgot the file :D


It uses $9 in the example but in the function itself pushes and pops like needed. If you want to perform the check in the installer you can use this function, it's optimized for that task:
http://nsis.sourceforge.net/archive/....php?pageid=79