如果已安装旧版本,则创建将执行更新的安装程序

Ben*_*Ben 19 inno-setup updates

我正在尝试为我的软件配置Inno设置(这是ac#软件).我计划发布我的软件的许多版本,如果我的应用程序的旧版本已经安装在计算机上,我想更改inno安装程序安装程序界面.在这种情况下,用户不应该能够更改安装目录.

有四种情况:

第一种情况:这是我的产品的第一次安装,inno设置应该正常进行.

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

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

第四种情况:安装程序版本与安装版本相同.如果需要,用户可以修复他的执行版本.

InnoSetup可以做到这一点吗?

Rob*_*beN 9

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

#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;
Run Code Online (Sandbox Code Playgroud)


Dea*_*nna 7

如果AppID在应用程序的生命周期内保持相同,Inno Setup已自动处理案例1,2和4 .
您还可以使用以下[Setup]指令隐藏目录和组页面:

DisableDirPage=auto
DisableGroupPage=auto
Run Code Online (Sandbox Code Playgroud)

有关更多详细信息,请参阅此ISXKB文章.

对于案例3,假设您的文件版本正确,Inno不会降级任何内容,但它实际上不会警告用户.要做到这一点,您需要添加代码来检查这一点,最有可能在InitializeSetup()事件函数中.

  • 实际上,如果您使用脚本向导创建脚本,那么应用程序文件的默认设置是添加`ignoreversion`标志,在这种情况下,降级实际上会降级所有文件.为了确认用户确实想要这样做,添加警告消息仍然是一个好主意,否则它应该可以正常工作 - 假设您的应用程序本身可以应对降级(例如数据兼容性问题).如果没有,那么您应该添加错误而不是警告. (2认同)