Archive: Finding an executable. ${Locate}


Finding an executable. ${Locate}
Good afternoon,

The task I'm trying to accomplish cannot be as difficult as it seems. It's just an installer that looks for a file name, anywhere on the System, and makes thats the default install path. I looked at the InstallDirRegKey function and it doesn't work for me, as there is no key.

Trying to get the ${Locate} thing work for me is failing me every way i can think of. I am not a professional programmer, but I do hobby stuff. Unfourtantley I can't find a single good example of the Locate function/macro being used that is complete code, just often Peusydo Code. Can somebody please, just show me an example or link me to an example where a there is a script that searches for a file, then changes the $INSTDIR to match that? I also want to append a directory to the returned path. For example, it should return (example: C:\programname\file.exe) i want to add \Data\Reports to that, so the default install string would be C:\programname\Data\Reports. Does anybody have any examples of that, that work. Thanks.


"Anywhere on the System" could be a long delay on script execution.

1st use ${GetDrives} (see the examples in nsis documentation) and then ${Locate} the file on the discovered drives, (also pretty plain examples in documentation).

You should add all the above in function .onInit if you want to change the $INSTDIR.


Originally posted by Red Wine
"Anywhere on the System" could be a long delay on script execution.

1st use ${GetDrives} (see the examples in nsis documentation) and then ${Locate} the file on the discovered drives, (also pretty plain examples in documentation).

You should add all the above in function .onInit if you want to change the $INSTDIR.
The examples are NOT good in the documentation, i have been going off them for about 2 hours. Thats why I'm here asking. I have found how to search for a file and get it into a variable name, but i still cant find how to append something too it.

${Locate} "C:\" "/L=FD /M=Program.exe " "FoundRB"
IfErrors 0 +2
MessageBox MB_OK "Error" IDOK +2
MessageBox MB_OK "$$R0=$R0"

Function FoundRB
StrCpy $R0 $R8
****StrCpy $R0 $R0 "\Data\Reports\"
StrCpy $0 StopLocate

Push $0
FunctionEnd



I can get it to find the file, but i want to take that 'found path' and add \data\reports onto it, but StrCpy instructions don't show how to append or merge or add, or combine or whatever you want to call sticking 2 strings together. I have tried every variation I could think of (as shown above with (****)) Nothing works.

So that way, when the $R0 variable gets returned, it will be c:\programlocation\Data\Reports as the install path. Also, i tried even getting the .onInit to work and it gives nothing but errors about trying to use ${Locate} in it.

Append text to a register:
StrCpy $R0 "$R0\Data\Reports\"


Originally posted by demiller9
Append text to a register:
StrCpy $R0 "$R0\Data\Reports\"


Yes, thank you that worked. I had just figured that out before checking back here :)

I have got this working now, however it only searches C:\

Function .onInit
${Locate} "C:\" "/L=FD /M=program.exe " "FoundRB"
StrCpy $INSTDIR $R0
FunctionEnd

Function FoundRB
StrCpy $R0 $R8
StrCpy $R0 "$R0\Data\Reports\"
StrCpy $0 StopLocate
Push $0
FunctionEnd

The one thing I notice is, however, it appears to be 'frozen' at the start (as it is searching the HDD). Is there a way to pop up a quick box , or text line , stating 'Searching for Installed Product'.. or something of that type.


${Locate} "C:\" is not good enough, you'd need a combination with the function ${GetDrives} if you want to search on every HDD available.


Example?
Quote:


It's not too hard. GetDrives has a callback function (basically a function that it calls lol) and in that function you can call Locate, like shown in this thread:
http://forums.winamp.com/showthread.php?threadid=264471

Stu


Originally posted by Afrow UK
It's not too hard. GetDrives has a callback function (basically a function that it calls lol) and in that function you can call Locate, like shown in this thread:
http://forums.winamp.com/showthread.php?threadid=264471

Stu
Thanks for the help. Since I'm doing this from the .onInit section, it just make the section too cumbersome, I will just have it search C: and if it's not there they can always click browse :)

Thanks again for all your help.


Originally posted by Red Wine
${Locate} "C:\" is not good enough, you'd need a combination with the function ${GetDrives} if you want to search on every HDD available. I have looked at the ${GetDrives} examples, and I don't see how I can embed the variables into the ${Locate} method? Could you give a brief example?

Thanks,