- NSIS Discussion
- Custom pages and registry settings
Archive: Custom pages and registry settings
Dragon_Z
10th March 2005 07:53 UTC
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
Afrow UK
10th March 2005 08:37 UTC
In the page's Leave function, use ReadINIStr to retrieve the Text string, and then write it to the registry using WriteRegStr.
-Stu
Dragon_Z
10th March 2005 08:54 UTC
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
Afrow UK
10th March 2005 12:21 UTC
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
Dragon_Z
10th March 2005 16:22 UTC
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
Afrow UK
10th March 2005 18:01 UTC
You are reading from INI file into $R0, but writing variable $R1 to registry.
-Stu
Dragon_Z
10th March 2005 19:39 UTC
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
Afrow UK
10th March 2005 20:15 UTC
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
Dragon_Z
11th March 2005 06:02 UTC
can you show me what it should look like, please? Thx
Installer
11th March 2005 07:04 UTC
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
kichik
11th March 2005 11:42 UTC
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.
RDaneel
11th March 2005 19:39 UTC
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...
Dragon_Z
12th March 2005 00:21 UTC
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
RDaneel
12th March 2005 00:35 UTC
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.
Dragon_Z
12th March 2005 04:12 UTC
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
Afrow UK
12th March 2005 15:40 UTC
It means you haven't declared the customPageALeave Function :D
You need to do it like:
Function customPageALeave
# ... code here ...
FunctionEnd
-Stu
Dragon_Z
12th March 2005 17:15 UTC
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
Afrow UK
12th March 2005 21:58 UTC
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
Dragon_Z
13th March 2005 00:35 UTC
it isn't capturing the text put in the boxes, nothing is diplayed in the popup
Afrow UK
13th March 2005 00:36 UTC
Oh wait, if you're reading from a Text field, then you ReadINIStr from "State" not "Text"
-Stu
Dragon_Z
13th March 2005 00:40 UTC
OK, thx now it works, thx for your patience, it is my first project