Archive: Pre-populate an INI


Pre-populate an INI
Description:
Using a custom page - i.e. somepage.ini - with a text box that is pre-populate with information from an INI or registry key string var. I have not yet found an example of how to do this.

Eventually it would be nice to populate the Field with an array of strings. If someone has an example of this it would be usefull.

What I am looking for is an example of a function that will push the text string var into a custom page during the install - i.e. post compile time.

Expectation:
I would expect that the user will not need to type in the required data.


Use ReadINIStr to get the values you need, then use the macro MUI_INSTALLOPTIONS_WRITE to write in the values.

Very offtopic: how many people do you guys know that hang out in this forum that would actually click this ad? lol

-dandaman32


Thanks Dan;

I ended up doing just that. I created a var and associated it with the registry key. I have provided a copy of my source code to show anyone who sees this later how to do the same thing. I am using XPUI (Experience UI) but you can use MUI or any other one that supports the write function.

;Create an .onInit function that checks to see if populated and if not interjects CompanyData as the default ODBC instance.


Function .onInit
ReadRegStr $TSWODBCData HKEY_LOCAL_MACHINE "Software\Company\General" "ODBCConnection"
ReadRegStr $CommonDesktop HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" "Common Desktop"
StrCmp $CompanyODBCData "" NoODBC ODBCExists
NoODBC:
StrCpy $CompanyODBCData "CompanyData"
ODBCExists:
FunctionEnd


; Add a new custom page below "!insertmacro XPUI_PAGE_COMPONENTS"


Page custom "ODBC_Connection" "GatherODBC"

; Add a function to extract, then populate(write) my custom field from the var above and then display the CompanyDataODBC.ini file.


Function ODBC_Connection

!insertmacro XPUI_INSTALLOPTIONS_EXTRACT "CompanyDataODBC.ini"
!insertmacro XPUI_INSTALLOPTIONS_WRITE "CompanyDataODBC.ini" "Field 3" "State" "$CompanyODBCData"
!insertmacro XPUI_INSTALLOPTIONS_DISPLAY "CompanyDataODBC.ini"

FunctionEnd

; Finally I capture the input with another function and update the registry key for future use.


Function GatherODBC
!insertmacro XPUI_INSTALLOPTIONS_READ $0 "CompanyDataODBC.ini" "Field 3" "State"
StrCpy $ODBCName "$0"
WriteRegStr HKEY_LOCAL_MACHINE "Software\Company\General" "ODBCConnection" "$ODBCName"
FunctionEnd

; OH and here is a copy of the CompanyDataODBC.ini file.


[Settings]
NumFields=3

[Field 1]
Type=Label
Text=This is the ODBC Name used locally on this computer. It links directly to the Database on the Microsoft SQL Server. If you have not already created an ODBC connection, please do so before continuing the installation.
Left=27
Right=231
Top=22
Bottom=57

[Field 2]
Type=Label
Text=Open Database Connectivity (ODBC) Name:
Left=9
Right=157
Top=6
Bottom=14

[Field 3]
Type=Text
State=TSWData
Left=43
Right=167
Top=68
Bottom=81