registryinstallationinno-setuppascalscript

Writing 32/64-bit specific registry key at the end of the installation in Inno Setup


I want to create an installer with Inno Setup, my first time using this tool.
What I’m trying to do is wrapping an existing installer of an existing software with a more detailed self-made installer (meaning a Setup.exe inside a Setup.exe).

What works for me after researching so far is asking the installer (Inno Setup *.exe) to run the included installer (actual software setup).
Why do I need another installer wrapped around? Because I want to give it some extra functions.

On particular thing is: I want to add a registry-key at the end of my installation, as the last step, fitting for relevant bit-system (32/64-bit). And here is where I'm asking expert-help, please. (main concern)

My problems in detail are as follows:

  1. I managed to add the key using the [Registry] section of Inno Setup. However, [Registry] seems to always run before [Run] – but I need the key added after the installation (added in a regedit-path the installation itself creates), not before, so I deleted what already worked (just in the wrong order) under [Registry]. For accomplishing a reg-add after the main-install, I found the two procedures AfterInstall and CurStepChanged/ssPostInstall, and DeinitializeSetup which seems not to fit so well for my concern (but thinking AfterInstall would be what I'm looking for(?!) since nothing more is supposed to come after and I think it won't run, if the install before already failed (?!).
  2. I don't know the Pascal-Syntax for adding a registry-key (string) under an existing path. I could add it under [Registry], however when it comes to the [Code]-section I feel a little lost even I did a lot of research by now about Inno Setup given functions and such.
  3. Third problem is that the path in the registry differs, depending on whether it's 32- or 64-bit System. So I actually need an extra query here checking the bit-System before adding either one or another path/key (because the install of the program itself creates the path depending on the bit-version already), I found the function IsWin64 (Boolean), now trying to mix a function (bit-version-query) with a procedure (AfterInstall) sounds even for me as a beginner wrong. Plus I tried to create an if-else-query, and the compiler told me I was doing it wrong. if IsWin64 then... works, but adding an else doesn't.

So the solution in theory would roughly be something like…

procedure MyAfterInstall();  
  function IsWin64: Boolean;  
      if 64-bit Reg-Add HKLM\SOFTWARE\Wow6432Node\A
      else Reg-Add HKLM\SOFTWARE\B

Sorry for not having to offer you more. I am not usually coding.

If relevant, that's what I have in my code-section so far:

[Code]
procedure DeinitializeSetup();
begin
  RegWriteStringValue(
    HKEY_LOCAL_MACHINE, 'SOFTWARE\Wow6432Node\A', 'ConnectionString ', 'Data Source=Test;');
end;

Reason why I used DeinitializeSetup was because it's one thing that worked for me so far, however I know that this function is called even if the user exits setup before anything is installed, which is not so good. I am running this after the install because the software-installation itself creates the path I want to add the key to, it makes no sense to have the key while the software install failed… Maybe there is a better way for that, too.
Apologies for many words, and thanks in advance for any help.


Solution

  • To execute a code after an installation finishes, use the CurStepChanged event function and check for CurStep = ssPostInstall.

    As Inno Setup is 32-bit application, by default it automatically gets redirected to the Wow6432Node on 64-bit systems. No need to do that explicitly. So if the Wow6432Node is the only difference between the 32-bit and 64-bit path, you do not need to do anything special:

    procedure CurStepChanged(CurStep: TSetupStep);
    begin
      if CurStep = ssPostInstall then
      begin
        Log('Installation finished, writing connection string');
        RegWriteStringValue(
          HKLM, 'SOFTWARE\A', 'ConnectionString', 'Data Source=Test;');
      end;
    end;
    

    Of course, unless you use 64-bit installation mode.

    See also: Writing 32/64-bit specific registry key in Inno Setup.


    If the key path really differs, use the IsWin64 function:

    procedure CurStepChanged(CurStep: TSetupStep);
    begin
      if CurStep = ssPostInstall then
      begin
        if IsWin64 then
        begin
          Log('Installation finished, writing 64-bit connection string');
          RegWriteStringValue(
            HKLM, 'SOFTWARE\A', 'ConnectionString', 'Data Source=Test;');
        end
          else
        begin
          Log('Installation finished, writing 32-bit connection string');
          RegWriteStringValue(
            HKLM, 'SOFTWARE\B', 'ConnectionString', 'Data Source=Test;');
        end;
      end;
    end;