Archive: Use SearchPath for Environment Variable???


Use SearchPath for Environment Variable???
I use SearchPath to find path for environment variable. However, I have some problems
My path in OS is C:\avalon-merlin-3.0-dist\merlin. I am worry because user may change this path during installing.
My code here:

Section "AddEnvMERLIN_HOME"
Push "MERLIN_HOME"
StrCmp $5 merlin.bat 0 +2
SearchPath $5 merlin.bat
StrCmp $5 "" 0 +2
MessageBox MB_OK "Avalon Merlin is not installed in your computer"
Push "C:\avalon-merlin-3.0-dist\merlin"
Call WriteEnvStr
SectionEnd

I am afraid that if the path of software is this:
"C:\avalon-merlin-3.0-dist\merlin\bin"
but I need to set environment variable is
"C:\avalon-merlin-3.0-dist\merlin"
I still look for help file but I can find a command which can trim a string.
And this code does not work,someone know why can help me!!
Thank you,


Use GetParent.


Thank Kichik,
When I do the way which you say, it inform "Avalon Merlin is not installed" although I install it in my computer,Can you tell me why???May I have some mistakes?

Section "AddEnvMERLIN_HOME"
Push "MERLIN_HOME"
StrCmp $5 "merlin.bat" 0 +2
SearchPath $5 "merlin.bat"
StrCmp $5 "" 0 +2
MessageBox MB_OK "Avalon Merlin is not installed in your computer"
Push $5
Call GetParent
Pop $5
Push $5
Call WriteEnvStr
SectionEnd

I still have one question, if you can would you give me some advice.
When I use GetParent I am worry about user can change default during installing
They install in C or D,eg:
C:\avalon merlin or D:\avalonmerlin
Not in C:\Program files\avalonmerlin\....
Can you help me!


I don't know why it wouldn't find merlin.bat after the change. Maybe the PATH isn't set right any more... Try reseting it.

As for the user changing the path, there's nothing you can do about the user changing things. You can only hope that kind of user would know what he's doing.