Best way to pass parameters to DLL, EXE which need quotes
Best way to pass parameters to DLL, EXE which need quotes
Hello:
Well almost done with my first installer script with InstallAware. I hope this is my last question:
I'm running a small Delphi program to rename a file's extension during a backup routine of previously installed files.
I need to pass it the file name, but the parameter must be wrapped in quotes since it includes spaces as part of the file path.
So if I pass $TARGETDIR$ this is properly expanded out, but how do I add quotes? Simply adding "$TARGETDIR$" or even $"TARGETDIR"$ does not work.
I saw COMMATEXT and ReplaceString, but there is no listing for COMMATEXT (or Set COMMATEXT) in the far right scripting function list.
So, do I use COMMATEXT or there a better way? If COMMATEXT how do I access this?
Thanks,
Chuck Belanger
Well almost done with my first installer script with InstallAware. I hope this is my last question:
I'm running a small Delphi program to rename a file's extension during a backup routine of previously installed files.
I need to pass it the file name, but the parameter must be wrapped in quotes since it includes spaces as part of the file path.
So if I pass $TARGETDIR$ this is properly expanded out, but how do I add quotes? Simply adding "$TARGETDIR$" or even $"TARGETDIR"$ does not work.
I saw COMMATEXT and ReplaceString, but there is no listing for COMMATEXT (or Set COMMATEXT) in the far right scripting function list.
So, do I use COMMATEXT or there a better way? If COMMATEXT how do I access this?
Thanks,
Chuck Belanger
-
MichaelNesmith
- Posts: 3452
- Joined: Thu Dec 22, 2005 7:17 pm
- Contact:
Why doesn't "$TARGETDIR$" work? It should.
Moreover, you can call a Win32 API directly using Call DLL Function instead of writing an external program for this simple task...
Moreover, you can call a Win32 API directly using Call DLL Function instead of writing an external program for this simple task...
Michael Nesmith
Install[b]Aware[/b]
[i]Home of The Next Generation MSI Installer[/i]
Get your free copy today - http://www.installaware.com/
Install[b]Aware[/b]
[i]Home of The Next Generation MSI Installer[/i]
Get your free copy today - http://www.installaware.com/
Hi, Michael:MichaelNesmith wrote:Why doesn't "$TARGETDIR$" work? It should.
Moreover, you can call a Win32 API directly using Call DLL Function instead of writing an external program for this simple task...
The little program I call creates a date string of sorts to use as an extension for the file I am trying to rename and keep as a backup. I'm not aware of any WinAPI calls to do this.
If I pass "$TARGETDIR$" what the program sees is $TARGETDIR$ not the expanded file directory.
It is true that passing the $TARGETDIR$ to a DLL does expand it and passes it properly.
So, how do you do this? and how does one access COMMATEXT? (My original question.)
Thanks,
Chuck Belanger
-
MichaelNesmith
- Posts: 3452
- Joined: Thu Dec 22, 2005 7:17 pm
- Contact:
You're confused. COMMATEXT is a data structure for passing data between the InstallAware engine and setup plug-ins at runtime.
I also don't know why "$TARGETDIR$" doesn't work for you. I just tried it right here and it was working swell - full expanded variable as expected.
Please double and triple check your findings before posting.
I also don't know why "$TARGETDIR$" doesn't work for you. I just tried it right here and it was working swell - full expanded variable as expected.
Please double and triple check your findings before posting.
Michael Nesmith
Install[b]Aware[/b]
[i]Home of The Next Generation MSI Installer[/i]
Get your free copy today - http://www.installaware.com/
Install[b]Aware[/b]
[i]Home of The Next Generation MSI Installer[/i]
Get your free copy today - http://www.installaware.com/
Michael:
Actually, I'm confused because there is nothing in the help file about COMMATEXT to indicate what or how it is used. That's not confusion its ignorance, because the help file has so little information. So, I was asking you, but all you give me is grief. It seemed like a possible solution to my issue that's all.
Also, I meant the literal "$TARGETDIR$" not simply $TARGETDIR$. And if you pass this, i.e. $TARGETDIR$, to an EXE in Run Program as, the EXE receives it as a series of string literals with spaces, thus a series of parameters, not what the program expects which is to have a string with embedded spaces be passed with quotes. You would never see this unless you actually show the passed params in a ShowMessage or something else as I did (delphi). So I doubt seriously if you are seeing what I'm talking about. If you pass the literal "$TARGETDIR$" the parameter shows up as "$TARGETDIR$", not the hoped for "<expanded>".
So, I have spent many hours on this one issue, not just double and triple checking what I'm asking. I have come from Wise installer which has a built in backup routine which I am trying to duplicate--and I got to say is difficult to do so in InstallAware.
So, I figured out a work around, but it would be nice to be able to do this within InstallAware.
Actually, I'm confused because there is nothing in the help file about COMMATEXT to indicate what or how it is used. That's not confusion its ignorance, because the help file has so little information. So, I was asking you, but all you give me is grief. It seemed like a possible solution to my issue that's all.
Also, I meant the literal "$TARGETDIR$" not simply $TARGETDIR$. And if you pass this, i.e. $TARGETDIR$, to an EXE in Run Program as, the EXE receives it as a series of string literals with spaces, thus a series of parameters, not what the program expects which is to have a string with embedded spaces be passed with quotes. You would never see this unless you actually show the passed params in a ShowMessage or something else as I did (delphi). So I doubt seriously if you are seeing what I'm talking about. If you pass the literal "$TARGETDIR$" the parameter shows up as "$TARGETDIR$", not the hoped for "<expanded>".
So, I have spent many hours on this one issue, not just double and triple checking what I'm asking. I have come from Wise installer which has a built in backup routine which I am trying to duplicate--and I got to say is difficult to do so in InstallAware.
So, I figured out a work around, but it would be nice to be able to do this within InstallAware.
MichaelNesmith wrote:You're confused. COMMATEXT is a data structure for passing data between the InstallAware engine and setup plug-ins at runtime.
I also don't know why "$TARGETDIR$" doesn't work for you. I just tried it right here and it was working swell - full expanded variable as expected.
Please double and triple check your findings before posting.
Thanks, Bokkie:
It may be that everyone is missing an important part of my question:
I'm passing this $TARGETDIR$ as a param to a RUN AS program. In that context it is passed very differently. Yes, it is expanded, but the program expects the parameters that are strings with embedded spaces to be in quotes and that is not how the EXE treats the passed parameter.
E.G.: if I'm passing a $TARGETDIR$\\Profviewer.exe which expands to: C:\\Program Files\\NMT\\NMT Professional Treeview\\Profviewer.exe
and the full param statement is:
$TARGETDIR$\\Profviewer.exe DATEEXT $TARGETDIR$\\BACKUP\\Profviewer.exe
The Delphi EXE which is expecting 3 parameters of the above, plus an action string (DATEEXT) and another file name, instead sees:
Param 1: C:\\Program
Param 2: Files\\NMT\\NMT
Param 3: Professional
What I want the EXE to see is:
Param 1: C:\\Program Files\\NMT\\NMT Professional Treeview\\Profviewer.exe
Param 2: DATEEXT
Param 3: C:\\Program Files\\NMT\\NMT Professional Treeview\\Backup\\Profviewer.exe
Granted if I use $TARGETDIR$ in any other InstallAware use, it expands or is used as expected/hoped. (dialog labels, messages, DLL params, etc)
Does that make the issue clearer?
Thanks,
Chuck
It may be that everyone is missing an important part of my question:
I'm passing this $TARGETDIR$ as a param to a RUN AS program. In that context it is passed very differently. Yes, it is expanded, but the program expects the parameters that are strings with embedded spaces to be in quotes and that is not how the EXE treats the passed parameter.
E.G.: if I'm passing a $TARGETDIR$\\Profviewer.exe which expands to: C:\\Program Files\\NMT\\NMT Professional Treeview\\Profviewer.exe
and the full param statement is:
$TARGETDIR$\\Profviewer.exe DATEEXT $TARGETDIR$\\BACKUP\\Profviewer.exe
The Delphi EXE which is expecting 3 parameters of the above, plus an action string (DATEEXT) and another file name, instead sees:
Param 1: C:\\Program
Param 2: Files\\NMT\\NMT
Param 3: Professional
What I want the EXE to see is:
Param 1: C:\\Program Files\\NMT\\NMT Professional Treeview\\Profviewer.exe
Param 2: DATEEXT
Param 3: C:\\Program Files\\NMT\\NMT Professional Treeview\\Backup\\Profviewer.exe
Granted if I use $TARGETDIR$ in any other InstallAware use, it expands or is used as expected/hoped. (dialog labels, messages, DLL params, etc)
Does that make the issue clearer?
Thanks,
Chuck
bokkie wrote:Chuck,
It works for me as well:
Set Variable QuotedDir to "$TARGETDIR$"
MessageBox: Dir, $TARGETDIR$ is now $QuotedDir$
-
MichaelNesmith
- Posts: 3452
- Joined: Thu Dec 22, 2005 7:17 pm
- Contact:
You're still confused 
First off, I'm really curious where you got on your track with COMMATEXT. Please enlighten before ranting any more about it.
Next, you could of course manually parse each command line parameter in Delphi, and assemble the whole command line parameter, but for some reason, you're still not getting my exact instructions, and are ending up more and more confused.
If you pass "$TARGETDIR$" WITH THE QUOTES it will work. Hopefully now the message gets across.
First off, I'm really curious where you got on your track with COMMATEXT. Please enlighten before ranting any more about it.
Next, you could of course manually parse each command line parameter in Delphi, and assemble the whole command line parameter, but for some reason, you're still not getting my exact instructions, and are ending up more and more confused.
If you pass "$TARGETDIR$" WITH THE QUOTES it will work. Hopefully now the message gets across.
Michael Nesmith
Install[b]Aware[/b]
[i]Home of The Next Generation MSI Installer[/i]
Get your free copy today - http://www.installaware.com/
Install[b]Aware[/b]
[i]Home of The Next Generation MSI Installer[/i]
Get your free copy today - http://www.installaware.com/
It also worked correctly on my machine:
shows in the commandline as
Rgds
Richard
Code: Select all
Write into Text File show.bat from Value echo %1$NEWLINE$pause (at end of file)
Set Variable TARGETDIR to C:\\program files\\install aware
Run Program show.bat "$TARGETDIR$" (WAIT)
Code: Select all
"C:\\program files\\install aware\\"
Richard
http://www.pointline.com
http://www.paraeasy.ch
http://ulrichard.ch
http://www.paraeasy.ch
http://ulrichard.ch
Hi, Michael:
Thanks for sticking with this and I apologize about my "rant."
Apparently, the late nights, the pressure made me hallucinate when I tried putting quotes around "$TARGETDIR$". In defense, I was trying a number of different things, including $"TARGETDIR"$--which does not work.
It works just fine with the delphi exe. I can even do "$TARGETDIR$"\\Filename.ext and the parameter is passed correctly.
When I was trying to figure out how to do this I was typing in various things in the help search and that's where I saw COMMATEXT. It sounded like a function which I could use to put quotes around my passed parameter string, but I guess not. That particular entry really is misleading because it does not give any context to COMMATEXT.
Thanks again,
Chuck
First off, I'm really curious where you got on your track with COMMATEXT. Please enlighten before ranting any more about it.
Next, you could of course manually parse each command line parameter in Delphi, and assemble the whole command line parameter, but for some reason, you're still not getting my exact instructions, and are ending up more and more confused.
If you pass "$TARGETDIR$" WITH THE QUOTES it will work. Hopefully now the message gets across.[/quote]
Thanks for sticking with this and I apologize about my "rant."
Apparently, the late nights, the pressure made me hallucinate when I tried putting quotes around "$TARGETDIR$". In defense, I was trying a number of different things, including $"TARGETDIR"$--which does not work.
It works just fine with the delphi exe. I can even do "$TARGETDIR$"\\Filename.ext and the parameter is passed correctly.
When I was trying to figure out how to do this I was typing in various things in the help search and that's where I saw COMMATEXT. It sounded like a function which I could use to put quotes around my passed parameter string, but I guess not. That particular entry really is misleading because it does not give any context to COMMATEXT.
Thanks again,
Chuck
First off, I'm really curious where you got on your track with COMMATEXT. Please enlighten before ranting any more about it.
Next, you could of course manually parse each command line parameter in Delphi, and assemble the whole command line parameter, but for some reason, you're still not getting my exact instructions, and are ending up more and more confused.
If you pass "$TARGETDIR$" WITH THE QUOTES it will work. Hopefully now the message gets across.[/quote]
-
MichaelNesmith
- Posts: 3452
- Joined: Thu Dec 22, 2005 7:17 pm
- Contact:
No worries 
Rule of thumb: any time you are passing command line parameters to a Windows application which has embedded spaces, enclose them in double quotes - this will pass the parameter as a single string. Otherwise, command line parameters are separated with each space. In Delphi, you can loop each of these using ParamCount and ParamStr, but why create the burden
So "$TARGETDIR$"\\something is also wrong. It must be "$TARGETDIR$\\something".
Rule of thumb: any time you are passing command line parameters to a Windows application which has embedded spaces, enclose them in double quotes - this will pass the parameter as a single string. Otherwise, command line parameters are separated with each space. In Delphi, you can loop each of these using ParamCount and ParamStr, but why create the burden
So "$TARGETDIR$"\\something is also wrong. It must be "$TARGETDIR$\\something".
Michael Nesmith
Install[b]Aware[/b]
[i]Home of The Next Generation MSI Installer[/i]
Get your free copy today - http://www.installaware.com/
Install[b]Aware[/b]
[i]Home of The Next Generation MSI Installer[/i]
Get your free copy today - http://www.installaware.com/

