在Inno Setup安装结束时编写32/64位特定的注册表项 [英] Writing 32/64-bit specific registry key at the end of the installation in Inno Setup

查看:156
本文介绍了在Inno Setup安装结束时编写32/64位特定的注册表项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用Inno Setup创建一个安装程序,这是我第一次使用此工具.
我想做的是将现有软件的现有安装程序与更详细的自制安装程序(意味着Setup.exe内的Setup.exe)包装在一起.

到目前为止,对我有用的是要求安装程序(Inno Setup * .exe)运行附带的安装程序(实际软件设置).
为什么需要包裹另一个安装程序?因为我想给它一些额外的功能.

关于某件事,是:我想在安装结束时添加一个注册表项,作为最后一步,以适合相关的位系统(32/64位).请在这里向我寻求专家帮助. (主要关注)

我的详细问题如下:

  1. 我设法使用Inno Setup的[Registry]部分添加了密钥.但是,[Registry]似乎总是在[Run]之前运行–但是我需要在安装后添加密钥(在安装本身创建的regedit路径中添加),而不是之前,所以我删除了已经起作用的文件(只是错误的订单)在[Registry]下.为了在主安装后完成reg-add,我发现了两个过程AfterInstallCurStepChanged/ssPostInstallDeinitializeSetup,这似乎不太适合我的关注(但是认为AfterInstall
  2. 如果我之前要安装的文件已经失败(?!),那么应该不会再有其他东西了,而且我认为它将无法运行,这就是我正在寻找的东西(?!).
  3. 我不知道在现有路径下添加注册表项(字符串)的Pascal语法.我可以在[Registry]下添加它,但是当涉及到[Code]部分时,即使到现在为止我对Inno Setup给出的功能等进行了大量研究,我仍然感到有些迷茫.
  4. 第三个问题是注册表中的路径不同,具体取决于它是32位还是64位系统.因此,实际上我在这里需要一个额外的查询来检查位系统,然后再添加一个或另一个路径/密钥(因为程序本身的安装已根据位版本创建了路径),我发现了函数IsWin64(布尔值),现在尝试将一个函数(位版本查询)与一个过程(AfterInstall)混合,即使对于初学者来说,这也对我来说是错误的.另外,我尝试创建一个if-else-query,编译器告诉我我做错了. if IsWin64 then...有效,但添加else无效.

因此,理论上的解决方案 大致类似于……

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

抱歉,不必为您提供更多服务.我通常不编码.

如果相关的话,这就是我到目前为止的代码部分中的内容:

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

之所以我使用DeinitializeSetup的原因是,到目前为止,这是对我有用的一件事,但是我知道即使用户在安装任何东西之前退出安装程序,该函数仍会被调用,这并不是很好.我在安装后运行此程序,因为软件安装本身会创建我要添加密钥的路径,在软件安装失败时拥有密钥是没有意义的……也许对此也有更好的方法. br> 谨致歉意,谢谢.

解决方案

要在安装完成后执行代码,请使用重定向到Wow6432Node在64位系统上.无需明确地执行此操作.因此,如果Wow6432Node是32位路径和64位路径之间的唯一区别,则无需执行任何特殊操作:

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

当然,除非您使用 64位安装模式. /p>

另请参阅:在Inno Setup中编写特定于32/64位的注册表项.


如果关键路径确实不同,请使用 IsWin64函数 :

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

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.

解决方案

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 to do anything special:

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssPostInstall then
  begin
    Log('Installation finished, writing connection string');
    RegWriteStringValue(
      HKEY_LOCAL_MACHINE, '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(
        HKEY_LOCAL_MACHINE, 'SOFTWARE\A', 'ConnectionString', 'Data Source=Test;');
    end
      else
    begin
      Log('Installation finished, writing 32-bit connection string');
      RegWriteStringValue(
        HKEY_LOCAL_MACHINE, 'SOFTWARE\B', 'ConnectionString', 'Data Source=Test;');
    end;
  end;
end;

这篇关于在Inno Setup安装结束时编写32/64位特定的注册表项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆