使用 Inno Setup 制作更新程序(识别32位和64位系统和是否安装原程序版本)

8 篇文章 2 订阅
4 篇文章 0 订阅

使用 Inno Setup 制作更新程序

HYPACK 官方的 HYPACK_2021_Q3_Update 程序更新是一个 HYPACK_2021_Q3_Update.zip 压缩包文件。

HYPACK 2021 Q3 Update原版更新包下载:https://hypack.s3.amazonaws.com/HYPACK_2021_Q3_Update.zip

HYPACK 2021.1.21.0 020121原版程序原版下载地址:
Win32位:https://hypack.s3.amazonaws.com/HYPACK+2021.1.21.0_32_020121.exe
Win64位:https://hypack.s3.amazonaws.com/HYPACK+2021.1.21.0_64_020121.exe

该文件需要释放压缩包,放到原安装程序中,为了方便简洁,特制作此 HYPACK_2021_Q3_Update 更新程序,使用 Inno Setup 制作。Inno 脚本代码做到识别32位和64位系统,读取相应的32位和64位系统注册表信息,根据注册表信息判断是否安装原程序版本,确定是否能更新程序。脚本代码完整可靠,已经通过32位和64位系统测试。适合各种程序制作安装更新包。

Inno 脚本代码如下:

//定义常量
#define MyAppName "HYPACK 2021 Q3 更新"
#define MyAppVersion "21.3.4.0"
#define MyAppPublisher "PureHM U.SInc"
#define MyAppURL "http://www.hypack.com"
#define MyAppSupportURL "https://www.hypack.com/customer-support"
#define MyAppUpdatesURL "https://www.hypack.com/customer-support/programs-and-updates"
#define MyAppExeName "HYPACK 2021 Q3 Update.exe"

[Setup]
//AppId的值为单独标识该应用程序。不要为其他安装程序使用相同的AppId值。 若要生成新的 GUID,可在菜单中点击 "工具|生成 GUID"。
;AppId={253087C2-C387-4B4E-8784-CB6A5E7528EA}
//应用程序名称
AppName={#MyAppName}
//应用程序版本
AppVersion={#MyAppVersion}
//应用程序发布者
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
//应用程序发布者网址
AppPublisherURL={#MyAppURL}
//应用程序支持网址
AppSupportURL={#MyAppSupportURL}
//应用程序更新网址
AppUpdatesURL={#MyAppUpdatesURL}
//创建应用程序目录
;CreateAppDir=yes
//默认目录名
DefaultDirName={code:GetDirName}
//文件安装前信息
;InfoBeforeFile= Languages\README.txt
;所需特权,注释以在非管理安装模式下运行(仅为当前用户安装)。
PrivilegesRequired=lowest
//输出编译安装文件名
OutputBaseFilename=HYPACK 2021 Q3 Update
//压缩类型 lzma2/ultra64  lzma
Compression=lzma2/ultra64 
//固实压缩
SolidCompression=yes
//向导样式
WizardStyle=modern
//禁用程序组页
DisableProgramGroupPage=yes
//可卸载
Uninstallable=no
//允许的架构
;ArchitecturesAllowed=x64
//打开64位安装模式
ArchitecturesInstallIn64BitMode=x64
//使用以前的应用程序目录
UsePreviousAppDir=yes
//目录存在警告
DirExistsWarning=no
//禁用目录页
DisableDirPage=yes
//默认开始菜单组名
DefaultGroupName=HYPACK 2021

[Languages]
Name: "zh"; MessagesFile: "compiler:Languages\Chinese.isl";InfoBeforeFile:Languages\README.txt;

[Icons]
//{commonprograms}     {commonstartmenu} {userstartmenu}
Name: "{group}\HYPACK 2021"; Filename:"{app}\Hypack.exe";WorkingDir:"{app}";Comment: "最优秀的 HYPACK 导航、地形测量程序"
Name: "{group}\HYPACK 2021 X64"; Filename:"{app}\x64\Hypack64.exe";WorkingDir:"{app}";Comment: "最优秀的 HYPACK 导航、地形测量程序" 
Name: "{group}\{cm:ProgramOnTheWeb,访问程序员博客}"; Filename:"https://blog.csdn.net/zyyujq" 

;生成开始菜单网站
Name: "{commondesktop}\HYPACK 2021"; Filename: "{app}\Hypack.exe";WorkingDir: "{app}";Comment: "最优秀的 HYPACK 导航、地形测量程序" 
Name: "{commondesktop}\HYPACK 2021 X64"; Filename:"{app}\x64\Hypack64.exe";WorkingDir:"{app}";Comment: "最优秀的 HYPACK 导航、地形测量程序" 
Name: "{commondesktop}\{cm:ProgramOnTheWeb,访问程序员博客}"; Filename:"https://blog.csdn.net/zyyujq" 

[Files]
Source: "{app}\acd.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "{app}\ADCPProfile.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "{app}\adcpviewer.exe"; DestDir: "{app}"; Flags: ignoreversion
;安装文件太多,不全部标识引用
;
;
; 注意: 不要在任何共享系统文件上使用“Flags: ignoreversion”


[Code]
//安装时判断系统中是否已安装该软件以前版本
function InitializeSetup(): Boolean;
var  strVer: String;

begin
  Result := true;
    if Is64BitInstallMode then
      //是64位操作系统
       begin
         if RegQueryStringValue(HKLM64,'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{FBFE3B0B-1BE8-4D54-879B-DB615FC70259}', 'DisplayVersion', strVer) then
            begin
              if not (strVer='1.21.0') then
                 begin
                   MsgBox('软件版本号错误:'#13#10#13#10'HYPACK 2021 Q3 升级仅支持 HYPACK 2021 V1.21.0 版本!', mbInformation, MB_OK);
                   Result := False;
                 end
               else
                 if not RegKeyExists(HKLM32, 'SOFTWARE\HYPACK\HYPACK 2021') then
                    begin
                      MsgBox('系统没有安装 HYPACK 2021.1.21.0 020121原版程序!'#13#10#13#10'请先安装原版程序后,再运行本更新程序!', mbInformation, MB_OK);
                      Result := False;
                    end;
             end
          else
             begin
               MsgBox('系统没有安装 HYPACK 2021.1.21.0 020121原版程序!'#13#10#13#10'请先安装原版程序后,再运行本更新程序!!', mbInformation, MB_OK);
               Result := False;
             end;
       end
       else
       //是32位操作系统
         begin
           if RegQueryStringValue(HKLM,'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{FBFE3B0B-1BE8-4D54-879B-DB615FC70259}', 'DisplayVersion', strVer) then
              begin
                if not (strVer='1.21.0') then
                   begin
                     MsgBox('软件版本号错误:'#13#10#13#10'HYPACK 2021 Q3 升级仅支持 HYPACK_2021 V1.21.0 版本!', mbInformation, MB_OK);
                     Result := False;
                   end
                 else
                   if not RegKeyExists(HKLM, 'SOFTWARE\HYPACK\HYPACK 2021') then
                      begin
                        MsgBox('系统没有安装 HYPACK 2021.1.21.0 020121原版程序!'#13#10#13#10'请先安装原版程序后,再运行本更新程序!', mbInformation, MB_OK);
                        Result := False;
                      end;
               end
            else
              begin
                MsgBox('系统没有安装 HYPACK 2021.1.21.0 020121原版程序!'#13#10#13#10'请先安装原版程序后,再运行本更新程序!!', mbInformation, MB_OK);
                Result := False;
              end;
         end;
end;

//获取注册表中该程序的安装路径
function GetDirName(Param: string): string;      //Param: string Value: string
var  InstallDir: string;
begin
  Result := 'C:\HYPACK 2021';
  if Is64BitInstallMode then
     begin
       if RegQueryStringValue(HKLM32, 'SOFTWARE\HYPACK\HYPACK 2021', 'InstallDir',InstallDir) then
          begin
              //MsgBox('安装路径为64: ' + InstallDir, mbInformation, MB_OK);
             Result := InstallDir;
              // InstallDir := ExtractFilePath( InstallDir);
          end;
     end
  else
     begin
       if RegQueryStringValue(HKLM, 'SOFTWARE\HYPACK\HYPACK 2021', 'InstallDir',InstallDir) then
          begin
            //MsgBox('安装路径为32: ' + InstallDir, mbInformation, MB_OK);
            Result := InstallDir;
            // InstallDir := ExtractFilePath( InstallDir);
          end;
     end;
end;

//检测操作系统版本
//function IsX64: Boolean;
//begin
//  Result := Is64BitInstallMode and (ProcessorArchitecture = paX64);
//end;

//function IsX32: Boolean;
//begin
//  Result :=not (Is64BitInstallMode and (ProcessorArchitecture = paX64));
//end;



  • 3
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

中游鱼

获取完整源代码,提高工作效率

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值