创建一个安装程序,如果已经安装了旧版本,它将执行更新 [英] Creating an installer that will perform an update if an older version is already installed

查看:215
本文介绍了创建一个安装程序,如果已经安装了旧版本,它将执行更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的软件(这是C#软件)配置Inno设置. 我计划发布软件的许多版本,如果计算机上已经安装了较早版本的应用程序,我想更改Inno安装程序的安装程序界面. 在这种情况下,用户将无法更改安装目录.

I am trying to configure Inno setup for my software (this is a C# software). I plan to release many versions of my software, I would like to change the Inno setup installer interface if an older version of my application is already installed on the computer. In this case, the user shouldn't be able to change the install directory.

有四种情况:

第一种情况:这是我产品的首次安装,Inno安装应正常进行.

First case: this is the first installation of my product, Inno setup should proceed normally.

第二种情况:已经安装了产品,并且安装程序包含较新的版本.用户无法选择目标文件夹.他可以运行更新.

Second case: the product is already installed AND the installer contains a newer version. The user cannot choose the destination folder. He can just run the update.

第三种情况:如果安装程序包含的版本比已安装的版本低,则该更新将被禁用,并显示一条消息.

Third case: If the installer contains an older version than the installed one, the update will be disabled and a message should be displayed.

第四种情况:安装程序版本与安装的版本相同.用户可以根据需要修复其实际版本.

Fourth case: The installer version is the same than the installed version. The user can repair his actual version if needed.

是否可以使用InnoSetup做到这一点?

Is it possible to do that with InnoSetup?

推荐答案

如果您想为用户提供一些反馈,可以尝试类似的方法. 首先,您的更新应与主应用程序具有相同的AppId名称. 然后,您可以设置一些检查,这些检查将显示消息以通知用户有关状态.

If you want to have some feedback for user you can try something like that. First of all, your update should have the same AppId name as your Main App. Then you can set some checks, that will display messages to inform user about the state.

#define MyAppVersion "1.2.2.7570"
#define MyAppName "MyApp Update"

[Setup]
AppId=MyApp
AppName={#MyAppName}
AppVersion={#MyAppVersion}
DefaultDirName={reg:HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MyApp_is1,InstallLocation}
DisableDirPage=True

[CustomMessages]
MyAppOld=The Setup detected application version 
MyAppRequired=The installation of {#MyAppName} requires MyApp to be installed.%nInstall MyApp before installing this update.%n%n
MyAppTerminated=The setup of update will be terminated.

[Code]
var
InstallLocation: String;

function GetInstallString(): String;
var
InstPath: String;
InstallString: String;
begin
InstPath := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\MyApp_is1');
InstallString := '';
if not RegQueryStringValue(HKLM, InstPath, 'InstallLocation', InstallString) then
RegQueryStringValue(HKCU, InstPath, 'InstallLocation', InstallString);
Result := InstallString;
InstallLocation := InstallString;
end;

function InitializeSetup: Boolean;
var
V: Integer;
sUnInstallString: String;
Version: String;
begin
    if RegValueExists(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\MyApp_is1', 'UninstallString') then begin
      RegQueryStringValue(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\MyApp_is1', 'DisplayVersion', Version);
      if Version =< ExpandConstant('{#MyAppVersion}') then begin 
          Result := True;
          GetInstallString();
       end
       else begin
MsgBox(ExpandConstant('{cm:MyAppOld}'+Version+'.'+#13#10#13#10+'{cm:MyAppRequired}'+'{cm:MyAppTerminated}'), mbInformation, MB_OK);
         Result := False;
  end;
end
else begin
  MsgBox(ExpandConstant('{cm:MyAppRequired}'+'{cm:MyAppTerminated}'), mbInformation, MB_OK);
  Result := False;
end;
end;

这篇关于创建一个安装程序,如果已经安装了旧版本,它将执行更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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