Archive: Custom pages and registry settings


Custom pages and registry settings
I have a custom page that I made and i would like whatever is put in the TEXT fields to be saved to the registry in windows.
Thx for any help you can provide.

[Settings]
NumFields=4

[Field 1]
Type=Label
Text=Name
Left=0
Right=-1
Top=0
Bottom=10

[Field 2]
Type=Text
Left=0
Right=-1
Top=10
Bottom=20


[Field 3]
Type=Label
Text=Serial Number
Left=0
Right=-1
Top=40
Bottom=50

[Field 4]
Type=Text
Left=0
Right=-1
Top=50
Bottom=60

In the page's Leave function, use ReadINIStr to retrieve the Text string, and then write it to the registry using WriteRegStr.

-Stu


sry, don't know where the documentation for that is, can you put it in one fo the example scripts so that I can figure out where it goes, Thx alot


ReadINIStr and WriteINIStr are in the NSIS documentation.
For example:

Page Custom customPage customPageLeave

Function customPageLeave
Push $R0
ReadINIStr $R0 "$PLUGINSDIR\ioFile.ini" "Field 1" "Text"
WriteRegStr HKCU "Software\MyApp" "Blah" "$R0"
Pop $R0
FunctionEnd


-Stu

It is creating the registry entryis now but it isn't putting anything in them. Thx for the help but I must be missing something.

Function customPageA
!insertmacro MUI_HEADER_TEXT "Registration" "$(TEXT_IO_SUBTITLE)"
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "registry.ini"
Push $R0
ReadINIStr $R0 "$PLUGINSDIR\registry.ini" "Field 2" "Text"
WriteRegStr HKCU "Software\AirSnare" "UserName" "$R0"
Pop $R0
Push $R1
ReadINIStr $R0 "$PLUGINSDIR\registry.ini" "Field 4" "Text"
WriteRegStr HKCU "Software\AirSnare" "Serial" "$R1"
Pop $R1
FunctionEnd


Same INI as above

You are reading from INI file into $R0, but writing variable $R1 to registry.

-Stu


OK, Thx but still there is nothing in the data field of the registry key


Function customPageA
!insertmacro MUI_HEADER_TEXT "Registration" "$(TEXT_IO_SUBTITLE)"
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "registry.ini"
Push $R0
ReadINIStr $R0 "$PLUGINSDIR\registry.ini" "Field 2" "Text"
WriteRegStr HKCU "Software\AirSnare" "UserName" "$R0"
Pop $R0
Push $R0
ReadINIStr $R0 "$PLUGINSDIR\registry.ini" "Field 4" "Text"
WriteRegStr HKCU "Software\AirSnare" "Serial" "$R0"
Pop $R0
FunctionEnd




[Settings]
NumFields=4

[Field 1]
Type=Label
Text=Name
Left=0
Right=-1
Top=0
Bottom=10

[Field 2]
Type=Text
Text=
Left=0
Right=-1
Top=10
Bottom=20


[Field 3]
Type=Label
Text=Serial Number
Left=0
Right=-1
Top=40
Bottom=50

[Field 4]
Type=Text
Text=
Left=0
Right=-1
Top=50
Bottom=60

This code needs to go in the page's Leave function:


Push $R0
ReadINIStr $R0 "$PLUGINSDIR\registry.ini" "Field 2" "Text"
WriteRegStr HKCU "Software\AirSnare" "UserName" "$R0"
ReadINIStr $R0 "$PLUGINSDIR\registry.ini" "Field 4" "Text"
WriteRegStr HKCU "Software\AirSnare" "Serial" "$R0"
Pop $R0


User input from the InstallOptions dialog are not saved to the INI file until after the user leaves the page. That's why you aren't getting any data.

Declare the Leave function like so:
Page Custom customPageA customPageALeave

-Stu

can you show me what it should look like, please? Thx


Custom pages and registry
hello Installers,

I have the same problem that you are faceing .
this is a small piece of script

Function SetContentServer
Push $R0
InstallOptions::dialog $PLUGINSDIR\ContentServer_Name.ini
Pop $R0
ReadINIStr $1 "$PLUGINSDIR\ContentServer_Name.ini" "Field 2" "Text"
FunctionEnd

Function SetContentServerLeave
; Push $1
WriteRegStr HKLM "Software\Legato\ContentServer" "ServerName" "$1"

FunctionEnd


If i put the text from the Page properties before compilation it writes into the registry. but If i take it from the user at runtime it does not.

Wht could be the issue?
why does "Var varname" variable decleration not work ?

Your help will be appreciated.

Regards

Parag


The leave function is called when the user clicks the next button, before the InstallOptions::dialog call returns. Simply write the value to the registry right after you read it in SetContentServer.


While not vastly experienced in custom pages, I do have *one* and use a slightly different model... :)

I use an .onInit to check the registry for an existing value for my field - if it is present, I directly update the corresponding field in the [now expanded] INI file.

BTW, since it makes sense for my case, I use the install options length-validating feature to enforce the length restrictions for my data entry field. This blocks the user from proceeding past that page until the restrictions are satisfied.

Then, in the body of the installer section - actually, just before it completes - I do a MUI_INSTALLOPTIONS_READ to get the value of the field, and save it to the registry with a WriteRegStr.

I am posting this both to make sure that my approach is sound (it does seem to work), and to mention that using the Leave function can have the side-effect of making a registry change (in the case described above) even if the user chooses to back out of (abort) the install...


this is all wonderful info and I hope to put it in my next installer, however, where should I place "Page Custom customPageA customPageALeave ", Thx


The "page custom..." would go in the midst of your "!insertmacro MUI_PAGE*" statements.

It is just saying that you have a custom page and that it has both Enter and Leave functions defined. The precise placement determines where in the sequence of pages making up your installer it appears.


tried it and got this error and it won't create any .exe now

Error: resolving leave-page function "customPageALeave" in install pages
Note: uninstall functions must begin with "un.", and install functions must not
Error - aborting creation process


Any Ideas? Thx

It means you haven't declared the customPageALeave Function :D

You need to do it like:
Function customPageALeave
# ... code here ...
FunctionEnd

-Stu


ok it actually made the Installer but now it still isn't writing the registry keys. See included zip with all the code and .ini's, thx for any help you can provide


Put "MessageBox MB_OK $R0" under the first ReadINIStr in your Leave function to see what the value of $R0 is.

Also you don't need the Pop and Push in the middle.

-Stu


it isn't capturing the text put in the boxes, nothing is diplayed in the popup


Oh wait, if you're reading from a Text field, then you ReadINIStr from "State" not "Text"

-Stu


OK, thx now it works, thx for your patience, it is my first project