Archive: Newb needs help with registry


Newb needs help with registry
Alright first of all, sorry that I don't know much, its hard to learn a new code from switching from a completely different installer that does everything 'automatically'.

I want a registry value to replace the path of $INSTDIR when my installer asks for the directory path. So i'm guessing I'll have to add a StrCpy in my script but I really dont know the commands for all of this.

Here's what I want to do exactly:

The installer changes the $INSTDIR according to a directory in the registry value. But the value also has -url %1 at the end that I don't need.

HKEY_CLASSES_ROOT\http\shell\open\command
String Value:

C:\PROGRA~1\FIREFOX\FIREFOX.EXE -url "%1"


If it displays something that doesn't contain 'Firefox' in the value then the installer will ignore it and continue with the default $INSTDIR

Now how would I go about doing all of this?

First of all welcome to NSIS.

To read a string from the registry use ReadRegStr command. Once you have the string you can use the StrStr function from the StrFunc.nsh include file to check for 'firefox'.

!include "StrFunc.nsh"
${StrStr} ;Active the StrStr Function

Function .onInit
ReadRegStr $1 HKCR "http\shell\open\command" ""
${StrStr} $0 "$1" "firefox"
StrCmp $0 "" no_firefox
;code for firefox
StrCpy $INSTDIR "whatever you want if firefox exists"
no_firefox:
;other code if needed
Function End
Hope this helps you out.

Vytautas ;)

Thanks a lot for the work. Well, now when I compile.. it gives me this error:

...<snip>StrCpy $R1 "$R2" () ($R4)
Pop: $R5
Pop: $R4
Pop: $R3
Pop: $R2
Exch($R1,0)
FunctionEnd
!insertmacro: end of FUNCTION_STRING_StrStr
Function: ".onInit"
Error: command Section not valid in function
Error in script "C:\Program Files\NSIS\first.nsi" on line 5 -- aborting creation process

It looks very strange to me.. as I don't know where its getting 'command Section not valid...'

Could you attach the script for testing. It appears that you inserted my code into a section, if thats the case you should remove the lines begining with 'function'. Although it's probably a better idea to configure the $INSTDIR variable in the .onInit function rather than in a section.

Vytautas


Here ya go.. I don't have it in a section thats why I was confused too. I was thinking maybe to add some Variables but I don't know how to use em.


Sorry, my fault, :igor: The last line in my code should be 'FunctionEnd' and NOT 'Function End'.

Sorry about all the confusion.

Vytautas :o


Ahhh... nice, it works now! :) Thanks man, I really appreciate it.

Alright I got two more questions

Is there a way without InstallOptions to add a checkbox to the Finish page and have it perform a function on exit?

Also, how do I copy a file into a folder thats randomly generated? I want something like:

Find userchrome-example.css inside the [*RANDOM*] folder
IfFileExists thispart
thispart:
File Myfile.css
CopyFiles Myfile.css [*RANDOM*]

For the finish page you should use this code:

!define MUI_FINISHPAGE_RUN
!define MUI_FINISHPAGE_RUN_FUNCTION 'yourfunctionname'

Vytautas :)

alright. one last question, i'm using the following code to convert my short path names (PROGRA~1 = PROGRAM FILES)

StrCpy $0 "C:\Progra~1"
StrCpy $1 ""
System::Call "Kernel32::GetLongPathNameA(t '$0', &t .r1, i \
${NSIS_MAX_STRLEN}) i .s"
Pop $0
IntCmp $0 ${NSIS_MAX_STRLEN} +2 +2 0
Abort "failed!"
DetailPrint "$0 - $1"
but it doesn't seem to work.

I'm trying to grab the value of my registry which is $5 to convert that to a long file name. Then using the result as my $INSTDIR

GetFullPathName /short user_var(output) path_or_file


Originally posted by deguix
GetFullPathName /short user_var(output) path_or_file
but thats to Shorten a Long File name.. I'm talking about Expanding a Short Name

Oh, sorry, I didn't read all... But I can help you, see this line you posted above?

System::Call "Kernel32::GetLongPathNameA(t '$0', &t .r1, i \
${NSIS_MAX_STRLEN}) i .s"
The result is returned to variable $1, as you specified on that bold part I marked.

You can use GetFullPathName to convert short file names to long file names:

StrCpy $0 "C:\PROGRA~1"
GetFullPathName $1 $0

; $1 = "C:\Program Files"

Still doesnt work.. all I need is it to convert my $5 to a long folder value and $7 will be the result

$5 is a ReadRegStr command btw

so now when im finished the $INSTLDIR will be $7


Do the folder you're trying to transform to long path form exists in your computer? It only works when exists the folder especified. Localizated Windows versions contain different folder names.


Alright so it works.. kinda

It spit out the C:\Program Files part but it removed the extra stuff after it :(

The registry key was like C:\PROGRA~1\FIREFOX

How would I make it display the text after Program Files?


Have you tried adding a \ to the end of the path?

Vytautas


GetFullPathName does not seem to work properly on my Win98SE system.

GetFullPathName $1 "C:\PROGRA~1"

; $1 = "C:\Program Files"

GetFullPathName $2 "C:\PROGRA~1\MOZILL~2"

; $2 = "C:\PROGRA~1\Mozilla Firefox"
I expected $2 to hold "C:\Program Files\Mozilla Firefox"

I can use GetParent to split the path up, convert each component and put them back together again but this is more work than I expected.

It's not your fault, it's NSIS fault. This a reproducable BUG. Thanks pengyou.

Using the System Plugin code above returns the correct result. Why doesn't GetFullPathName return the right value as it should?


Hmm.. how bout an easier way

Is there a faster way to just like copy and change the strings:

change from $1(my registry which contains short names)
PROGRA~ = Program Files
MOZILL~ = Mozilla
to $INSTDIR


what about my random folder idea? anyone know how I would do that?


Use ${StrRep} from StrFun.nsh, or see the Archive for String Replacer.

About random, use nsRandom plugin from Archive downloads.