How to detect and install prerequisite(s) using Inno? [duplicate]

为君一笑 提交于 2020-07-20 05:45:09

问题


I need to install some prerequisites for an app using Inno. I want the prerequisites to only install if the prerequisite does not exist or is an earlier version. I have found some solutions such as:

[Code]
procedure InstallFramework;
var
  ResultCode: Integer;
begin
  if not Exec(ExpandConstant('{tmp}\NDP472-KB4054530-x86-x64-AllOS-ENU.exe'), '/q /norestart', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then
  begin
    { you can interact with the user that the installation failed }
    MsgBox('.NET installation failed with code: ' + IntToStr(ResultCode) + '.',
      mbError, MB_OK);
  end;
end;

That does not look like it checks to see if the framework exists already or what version may already be installed.

What is the pattern to use to look for a previously installed version, if it exists then check version and if version is older or does not exist then install?


回答1:


This a simple answer to head you in one of many possible solutions.

In the testing environment (or in your computer) you install the application and all the required components, so you have them appear in the control panel's Programs and Features

Then you search in the registry for the name that appears in the Programs and Features

You want to find the value DisplayName that contains that name. You'll find it in one key of

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\, HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\

or

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall

, depending of the type of installation.

Note: Some components can be hidden from the Programs and Features if the value SystemComponent is 1 in the correspondent key.

Then you can check the registry key existence with something like this in pascal script

[Code]
function test(bitness: integer; productCode: String): Boolean;
begin
    if RegValueExists(bitness, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\' + productCode, 'DisplayName') then Result := True else Result := False;
end;

You can call this function inside function PrepareToInstall(var NeedsRestart: Boolean): String; or using check parameters (search in inno setup help)



来源:https://stackoverflow.com/questions/57208765/how-to-detect-and-install-prerequisites-using-inno

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!