Page 1 of 1

Inno setup features - part 2 copying files to applcation data folder and setting registry values

#1 aniri  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 54
  • View blog
  • Posts: 657
  • Joined: 24-November 09

Posted 24 February 2010 - 02:40 AM

This is the second part of the innosetup tutorial. I will describe another feature you might want to add to your installer.

If your program needs certain files to run, you will have to copy those files on the userís computer and save the path to be able to use it when running the program.
The usual place where these types of files are found is the application data folder on the computer (usually: c:\Documents and Settings\All Users\Application Data). You may want to save the data in the All Users folder or only in the current userís folder. Also, you will need to save that path so you can use it from your application. The path can be saved in a registry value.

I will show you how to make the installer ask the user if they want to install the application for all users or just the current user, and copy the necessary files to the specified folder. It will also save the path to the registry so the application can use it.

We will add two tasks to the additional [Tasks] section of the installer:
[Tasks]
Name: common; Description: "&All users"; GroupDescription: "Install For:"; Flags: exclusive unchecked
Name: local;  Description: "Just &me"; GroupDescription: "Install For:"; Flags: exclusive



Two radio buttons will be shown and the user will choose who to install the application for.

We will use a small function in the [ Code ] section to save the users selection:

[Code]
function AppDataFolder(Param: String): String;
begin
  if IsTaskSelected('common') then
    Result := ExpandConstant('{commonappdata}')
  else
    Result := ExpandConstant('{localappdata}')
end; 



{commonappdata} and {localappdata} are paths set by innosetup. {localappdata} is the path to the local Application Data folder, and {commonappdata} is the path to the Application Data folder available for all users.

We have to add the following code to the [Files] section to copy the files in the selected folder:

Source: "source_path\file_to_copy.extension"; DestDir: "{code: AppDataFolder}\My folder\file-to-copy.extension"; Flags: ignoreversion



Add this line for every file you need to copy.

Notice that we use the destination path returned by the function: "{code: AppDataFolder}

The only thing left to do is save the path value in the registry. We will add a registry section to our innosetup script:

[Registry]
Root: HKLM; Subkey: "Software\My folder"; Flags: uninsdeletekeyifempty
Root: HKLM; Subkey: "Software\ My folder "; ValueType: string; ValueName: "UserPath"; ValueData: "{code: AppDataFolder}\Ropeco My folder "



A key with the value returned by the AppDataFolder function will be saved in the HKLM\Software\My folder registry key.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1