Inno Setup: Use data from custom wizard page in Registry section - inno-setup

I'd like to know how to use values from a user input from a custom wizard page. I have a custom page, on which the user types the ODBC connection data. This is the code for this part:
ServerDataPage := CreateInputQueryPage(AskAuthPage.ID,
'SQL Server Connection Data', '',
'Please insert data...');
ServerDataPage.Add('ODBC Name:', False);
ServerDataPage.Add('Server Name:', False);
ServerDataPage.Add('User:', False);
ServerDataPage.Add('Password:', False);
This is pretty much working as it should. The page appears with the input boxes and captions.
I also looked up a example from Inno Setup. There's this line:
ExamplePage.Values[0] := GetPreviousData('Name', ExpandConstant('{sysuserinfoname}'));
So I thought there has to be a "backward" thing, such as:
thisIsAVariable := ServerDataPage.Values[x]
Could I use these variables to create an ODBC like this?
Root: HKCU; SubKey: Software\ODBC\ODBC.INI\ODBC Data Sources; ValueType: string; ValueName: Leist; ValueData: SQL Server; Flags: createvalueifdoesntexist uninsdeletevalue
Root: HKCU; SubKey: Software\ODBC\ODBC.INI\Leist; Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: Driver; ValueType: string; ValueData: {sys}\SQLSRV32.dll
Root: HKCU; SubKey: Software\ODBC\ODBC.INI\Leist; Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: Server; ValueType: string; ValueData: SERVERADRESS
Root: HKCU; SubKey: Software\ODBC\ODBC.INI\Leist; Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: Database; ValueType: string; ValueData: DATABASE NAME
Root: HKCU; SubKey: Software\ODBC\ODBC.INI\Leist; Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: LastUser; ValueType: string; ValueData: USER
Root: HKCU; SubKey: Software\ODBC\ODBC.INI\Leist; Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: Password; ValueType: string; ValueData: PASSWORD
And if so, where do I have to put this in the script? The whole "custom wizard pages" thing is in the [Code] section. Are these variables also usable outside this [Code] section?
Greetings

Use a scripted constant to use the values from the custom page in the [Registry] (or any other) section:
[Registry]
Root: HKCU; SubKey: Software\ODBC\ODBC.INI\ODBC Data Sources; \
ValueType: string; ValueName: Leist; ValueData: SQL Server; \
Flags: createvalueifdoesntexist uninsdeletevalue
Root: HKCU; SubKey: Software\ODBC\ODBC.INI\Leist; \
Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: Driver; \
ValueType: string; ValueData: {sys}\SQLSRV32.dll
Root: HKCU; SubKey: Software\ODBC\ODBC.INI\Leist; \
Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: Server; \
ValueType: string; ValueData: {code:GetServerData|0}
Root: HKCU; SubKey: Software\ODBC\ODBC.INI\Leist; \
Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: Database; \
ValueType: string; ValueData: {code:GetServerData|1}
Root: HKCU; SubKey: Software\ODBC\ODBC.INI\Leist; \
Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: LastUser; \
ValueType: string; ValueData: {code:GetServerData|2}
Root: HKCU; SubKey: Software\ODBC\ODBC.INI\Leist; \
Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: Password; \
ValueType: string; ValueData: {code:GetServerData|3}
[Code]
var
ServerDataPage: TInputQueryWizardPage;
function GetServerData(Param: string): string;
begin
Result := ServerDataPage.Values[StrToInt(Param)];
end;

Related

Using the Tasks parameter with Registry key entries in Inno Setup script

I have discussed this task before about file associations. But something just came to my mind.
Here are the task deinifions:
[Tasks]
Name: "register32"; Description: "Meeting Schedule Assistant (32 bit)"; GroupDescription: "{cm:FileAssociations}"; Flags: unchecked exclusive; Check: IsWin64
Name: "register64"; Description: "Meeting Schedule Assistant (64 bit)"; GroupDescription: "{cm:FileAssociations}"; Flags: exclusive; Check: IsWin64
Here are the registry keys:
[Registry]
; ==================================================
; Register File Types
Root: "HKCR"; Subkey: ".mwb"; ValueType: string; ValueData: "MeetSchedAssist.MWB"; Flags: uninsdeletevalue
Root: "HKCR"; Subkey: ".srr"; ValueType: string; ValueData: "MeetSchedAssist.SRR"; Flags: uninsdeletevalue
Root: "HKCR"; Subkey: "MeetSchedAssist.MWB"; ValueType: string; ValueData: "Meeting Workbook Schedule"; Flags: uninsdeletekey
Root: "HKCR"; Subkey: "MeetSchedAssist.SRR"; ValueType: string; ValueData: "Assignments Report"; Flags: uninsdeletekey
Root: "HKCR"; Subkey: "MeetSchedAssist.MWB\Shell\Open\Command"; ValueType: string; ValueData: """{app}\{code:GetExecutableToRegister}"" ""%1"""; Flags: uninsdeletekey
Root: "HKCR"; Subkey: "MeetSchedAssist.SRR\Shell\Open\Command"; ValueType: string; ValueData: """{app}\{code:GetExecutableToRegister}"" ""%1"""; Flags: uninsdeletekey
; ==================================================
Shouldn't the above registry keys have a Tasks parameter? Like this:
Root: "HKCR"; \
Subkey: ".mwb"; \
ValueType: string; \
ValueData: "MeetSchedAssist.MWB"; \
Flags: uninsdeletevalue; \
Tasks: register32 register64
I am just not sure because one one of those tasks need to be ticked by the user, not both.
No, you should not put Tasks: register32 register64 there.
You want those Registry entries be processed always, don't you?
On 32-bit system the entries would not be processed, as neither of the tasks exist (due to Check: IsWin64).
Your tasks exist only to select the executable (GetExecutableToRegister), not to select whether and what keys to create.

Inno Setup give user choice of which application to associate extensions with

I have a setup project which installs three different executables.
I want to give users to option of associating multiple file extensions with either one of the exes or none of them. Is this possible, if so how?
The code I currently use to associate a single program with a file extension is:
[Registry]
Root: HKCR; Subkey: "program1\DefaultIcon"; ValueType: string; \
ValueName: ""; ValueData: "{app}\program1.EXE,0"
Root: HKCR; Subkey: "program1\shell\open\command"; ValueType: string; \
ValueName: ""; ValueData: """{app}\program1.exe"" ""%1"""
You can use the "Tasks" to present a selection.
For example:
[Tasks]
Name: associate; Description: "Associate application with extension"
Name: associate\app1; Description: "Application 1"; Flags: exclusive
Name: associate\app2; Description: "Application 2"; Flags: exclusive unchecked
Name: associate\app3; Description: "Application 3"; Flags: exclusive unchecked
Then use the Task parameter in a respective section to select the correct operation for the registration.
In your case (association), it would be either
the [Registry] section, if you let the installer do the registration or
the [Run] section, if you delegate the registration to some application.
Example for your [Registry] section entries:
[Registry]
Root: HKCR; Subkey: "program1\DefaultIcon"; ValueType: string; ValueName: ""; \
ValueData: "{app}\program1.EXE,0"; Tasks: associate\app1
Root: HKCR; Subkey: "program1\shell\open\command"; ValueType: string; ValueName: ""; \
ValueData: """{app}\program1.exe"" ""%1"""; Tasks: associate\app1
Root: HKCR; Subkey: "program1\DefaultIcon"; ValueType: string; ValueName: ""; \
ValueData: "{app}\program2.EXE,0"; Tasks: associate\app2
Root: HKCR; Subkey: "program1\shell\open\command"; ValueType: string; ValueName: ""; \
ValueData: """{app}\program2.exe"" ""%1"""; Tasks: associate\app2
Root: HKCR; Subkey: "program1\DefaultIcon"; ValueType: string; ValueName: ""; \
ValueData: "{app}\program3.EXE,0"; Tasks: associate\app3
Root: HKCR; Subkey: "program1\shell\open\command"; ValueType: string; ValueName: ""; \
ValueData: """{app}\program3.exe"" ""%1"""; Tasks: associate\app3
(I'm not sure about your program1 key, shouldn't it be an extension or file type?)
To avoid repeating almost the same Registry entries, you can use a scripted constant:
[Registry]
Root: HKCR; Subkey: "program1\DefaultIcon"; ValueType: string; ValueName: ""; \
ValueData: "{app}\{code:AssociateExecutable},0"; Tasks: associate
Root: HKCR; Subkey: "program1\shell\open\command"; ValueType: string; ValueName: ""; \
ValueData: """{app}\{code:AssociateExecutable}"" ""%1"""; Tasks: associate
[Code]
function AssociateExecutable(Param: string): string;
begin
if IsTaskSelected('associate\app1') then Result := 'program1.exe'
else
if IsTaskSelected('associate\app2') then Result := 'program2.exe'
else
if IsTaskSelected('associate\app3') then Result := 'program3.exe'
else
begin
Log('No application selected, this should not happen');
Result := '';
end;
end;

Stopping a rollback from deleting registry keys if its a 2nd or 3rd install

I have an installer and have been handling upgrades just by installing over the top of the last install. This works just fine but I noticed that if it is the 2nd or 3rd or whatever install and something fails when the files are being written and a rollback is performed then any registry entries are deleted.
So is it possible to have INNO restore the previous keys?
My code looks like this:
[Registry]
Root: "HKLM"; Subkey: "SOFTWARE\NGT"; Flags: noerror
Root: "HKLM"; Subkey: "SOFTWARE\NGT\i2tApp"; ValueType: string; ValueName: "pathSvr"; ValueData: "{app}"; Flags: noerror uninsdeletekey
Root: "HKLM"; Subkey: "SOFTWARE\NGT\i2tApp"; ValueType: string; ValueName: "pathResp"; ValueData: "{code:GetResponseDir}"; Flags: noerror uninsdeletekey;
Root: "HKLM"; Subkey: "SOFTWARE\NGT\i2tApp"; ValueType: string; ValueName: "unInstallerEXE"; ValueData: "unins000.exe"; Flags: noerror uninsdeletekey
Root: "HKLM"; Subkey: "SOFTWARE\NGT\i2tApp"; ValueType: string; ValueName: "path2PrevInstalls"; ValueData: "{app}"; Flags: noerror uninsdeletekey
Root: "HKLM"; Subkey: "SOFTWARE\NGT\i2tApp"; ValueType: string; ValueName: "softwareName"; ValueData: "{#MyAppName}"; Flags: noerror uninsdeletekey
Root: "HKLM"; Subkey: "SOFTWARE\NGT\i2tApp"; ValueType: string; ValueName: "currentVersion"; ValueData: "{#MyAppVersion}"; Flags: noerror uninsdeletekey
I have tried different flags but it seems to me I might have to hand code this. Any ideas?

Inno Setup: File Association not working

I'm trying to associate a filetype with my program with Inno Setup 5.5.4 (u). This somehow does not work: no program is associated to my extension and no icon in being shown in explorer.
Note that when copying the registry values found in regedit and pasting them into explorer, the icon and the program open, respectively.
Here is my code, nearly identical to the one present in the Inno FAQ.
[Registry]
Root: HKCR; Subkey: ".wcalc"; ValueType: string; ValueName: ""; ValueData: "{#MyAppName}"; Flags: uninsdeletevalue
Root: HKCR; Subkey: "{#MyAppName}"; ValueType: string; ValueName: ""; ValueData: "BHKW-Calc Datei"; Flags: uninsdeletekey
Root: HKCR; Subkey: "{#MyAppName}\DefaultIcon"; ValueType: string; ValueName: ""; ValueData: "{app}\icon.ico,0"
Root: HKCR; Subkey: "{#MyAppName}\shell\open\command"; ValueType: string; ValueName: ""; ValueData: """{app}\{#MyAppExeName}"" ""%1"""
Any idea of what could be wrong?

How to change file associations in Inno-setup

I need the user to be able to double click on a .pdb file and have it open with myPgm.exe.
What is the syntax to associate a file type (myData.pdb) with an executable (myPgm.exe)?
Is it a registry entry?
There's an entry for that in the FAQ on the Inno Setup web site. Here is the quote of the relevant section of the FAQ:
Creating File Associations
First set the [Setup] section directive ChangesAssociations to yes. Then create [Registry] entries as shown below.
[Registry]
Root: HKCR; Subkey: ".myp"; ValueType: string; ValueName: ""; ValueData: "MyProgramFile"; Flags: uninsdeletevalue
".myp" is the extension we're associating. "MyProgramFile" is the internal name for the file type as stored in the registry. Make sure you use a unique name for this so you don't inadvertently overwrite another application's registry key.
Root: HKCR; Subkey: "MyProgramFile"; ValueType: string; ValueName: ""; ValueData: "My Program File"; Flags: uninsdeletekey
"My Program File" above is the name for the file type as shown in Explorer.
Root: HKCR; Subkey: "MyProgramFile\DefaultIcon"; ValueType: string; ValueName: ""; ValueData: "{app}\MYPROG.EXE,0"
"DefaultIcon" is the registry key that specifies the filename containing the icon to associate with the file type. ",0" tells Explorer to use the first icon from MYPROG.EXE. (",1" would mean the second icon.)
Root: HKCR; Subkey: "MyProgramFile\shell\open\command"; ValueType: string; ValueName: ""; ValueData: """{app}\MYPROG.EXE"" ""%1"""
"shell\open\command" is the registry key that specifies the program to execute when a file of the type is double-clicked in Explorer. The surrounding quotes are in the command line so it handles long filenames correctly.
A File association is a series of Registry entries. For more info, take a look at How to Use File Associations Microsoft Sample.
If you don't want to create system-wide file associations, you can create specific user file associations too.
To create registry entries from your script, read the ISS Documentation: Registry Section. If you find any problems come back with a more specific question.
that works well for me.
just rename MYEXTENSION
[Registry]
Root: HKA ; Subkey: "Software\Classes\.MYEXTENSION"; ValueData: "{#MyAppName}"; Flags: uninsdeletevalue; ValueType: string; ValueName: ""
Root: HKA ; Subkey: "Software\Classes\{#MyAppName}"; ValueData: "{app}\{#MyAppExeName}"; Flags: uninsdeletekey; ValueType: string; ValueName: ""
Root: HKA ; Subkey: "Software\Classes\{#MyAppName}\DefaultIcon"; ValueData: "{app}\{#MyAppExeName},0"; ValueType: string; ValueName:""
Root: HKA ; Subkey: "Software\Classes\{#MyAppName}\shell\open\command"; ValueData: """{app}\{#MyAppExeName}"" ""%1"""; ValueType: string; ValueName: ""
#define MyAppAssocExt ".mp3"
and
[Registry]
Root: HKA; Subkey: "Software\Classes\{#MyAppAssocExt}\OpenWithProgids"; ValueType: string; ValueName: "{#MyAppAssocKey}"; ValueData: ""; Flags: uninsdeletevalue
Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey}"; ValueType: string; ValueName: ""; ValueData: "{#MyAppAssocName}"; Flags: uninsdeletekey
Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey}\DefaultIcon"; ValueType: string; ValueName: ""; ValueData: "{app}\{#MyAppExeName},0"
Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey}\shell\open\command"; ValueType: string; ValueName: ""; ValueData: """{app}\{#MyAppExeName}"" ""%1"""
Root: HKA; Subkey: "Software\Classes\Applications\{#MyAppExeName}\SupportedTypes"; ValueType: string; ValueName: ".myp"; ValueData: ""
[Icons]
Name: "{group}\도깨비 플레이어"; Filename: "{app}\XMPlayer.exe"
Name: "{userdesktop}\도깨비 플레이어"; Filename: "{app}\XMPlayer.exe"; WorkingDir: "{app}"; IconFilename: "{app}\XMPlayer.exe";
Name: "{group}\{cm:UninstallProgram,Goblin Player}"; Filename: "{uninstallexe}";

Resources