; 云仓视频溯源软件 —— EXE 安装包定义(Inno Setup 6) ; ; 为什么要有 EXE 版: ; MSI 依赖 Windows Installer 服务(msiserver)。现场有一部分电脑把该服务禁用 / 被安全软件拦 / ; 组策略禁止 MSI,导致双击安装包直接失败。EXE 版只用「解压 + 复制文件 + 写 HKCU」, ; 完全不碰 Windows Installer,安装目录、注册表项、快捷方式与 MSI 版保持一致,可以互相顶替。 ; ; 与 MSI 版的对应关系: ; - 同一个安装目录 %LOCALAPPDATA%\Programs\YuncangTrace; ; - 同样注册 yuncang:// 协议(HKCU\Software\Classes\yuncang); ; - 同样是 perUser 安装(不需要管理员/UAC)。 ; ; 安装旧版 MSI 的机器再装本 EXE 时,[Code] 里会先静默卸载旧 MSI,避免「应用和功能」里 ; 留下两个条目(旧 MSI 卸载会删掉本 EXE 装的文件)。 ; ; 编译(build.ps1 -Target Exe 会自动调用): ; ISCC.exe /DVersion=1.0.0 /Oout YuncangTrace.iss ; 产物:out\YuncangTraceSetup-<版本>.exe ; ; 静默安装(自动更新用): ; YuncangTraceSetup-<版本>.exe /VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP- #ifndef Version #define Version "0.0.0" #endif [Setup] ; AppId 与 MSI 的 UpgradeCode 保持一致:同一个产品、同一个安装位置,升级时能识别出旧版本 AppId={{A1E7CF0F-4FC5-4A88-84B5-13E818F352CC} AppName=云仓视频溯源软件 AppVersion={#Version} AppVerName=云仓视频溯源软件 {#Version} AppPublisher=云仓 DefaultDirName={localappdata}\Programs\YuncangTrace DefaultGroupName=云仓视频溯源软件 DisableProgramGroupPage=yes DisableDirPage=auto OutputDir=out OutputBaseFilename=YuncangTraceSetup-{#Version} SetupIconFile=..\Assets\app.ico UninstallDisplayIcon={app}\YuncangTrace.LocalService.exe UninstallDisplayName=云仓视频溯源软件 ; perUser:不需要管理员,也就不受「安装 MSI 要管理员」这类限制影响 PrivilegesRequired=lowest ArchitecturesAllowed=x64compatible ArchitecturesInstallIn64BitMode=x64compatible Compression=lzma2/max SolidCompression=yes WizardStyle=modern ; 装/升级时先让正在运行的软件退出,避免 exe 被占用换不掉 CloseApplications=yes RestartApplications=no AllowNoIcons=yes SetupLogging=yes VersionInfoVersion={#Version} VersionInfoCompany=云仓 VersionInfoDescription=云仓视频溯源软件 安装程序 VersionInfoProductName=云仓视频溯源软件 VersionInfoProductVersion={#Version} [Files] Source: "..\publish\YuncangTrace.LocalService.exe"; DestDir: "{app}"; Flags: ignoreversion ; 海康运行库(HCNetSDK.dll + HCNetSDKCom\*):取通道/取流必需 Source: "..\publish\native\*"; DestDir: "{app}\native"; Flags: ignoreversion recursesubdirs createallsubdirs ; 谷歌浏览器插件:菜单「工具 → 复制谷歌插件地址」给出的就是这个目录 Source: "..\publish\extension\*"; DestDir: "{app}\extension"; Flags: ignoreversion recursesubdirs createallsubdirs [Icons] Name: "{group}\云仓视频溯源软件"; Filename: "{app}\YuncangTrace.LocalService.exe"; WorkingDir: "{app}"; Comment: "本机打印与溯源服务(打开后最小化到托盘)" [Registry] ; yuncang:// 启动协议(安装即生效,卸载时删除) Root: HKCU; Subkey: "Software\Classes\yuncang"; ValueType: string; ValueData: "URL:云仓视频溯源软件"; Flags: uninsdeletekey Root: HKCU; Subkey: "Software\Classes\yuncang"; ValueType: string; ValueName: "URL Protocol"; ValueData: ""; Flags: uninsdeletekey Root: HKCU; Subkey: "Software\Classes\yuncang\shell\open\command"; ValueType: string; ValueData: """{app}\YuncangTrace.LocalService.exe"" ""%1"""; Flags: uninsdeletekey [Run] Filename: "{app}\YuncangTrace.LocalService.exe"; Description: "启动云仓视频溯源软件"; Flags: nowait postinstall skipifsilent [Code] const UninstallKey = 'Software\Microsoft\Windows\CurrentVersion\Uninstall'; AppDisplayName = '云仓视频溯源软件'; function HasParam(const Value: String): Boolean; var I: Integer; begin Result := False; for I := 1 to ParamCount do if CompareText(ParamStr(I), Value) = 0 then begin Result := True; Exit; end; end; { 卸载旧 MSI 版:只认 UninstallString 里有 msiexec 的同名条目,不碰 EXE 版自己 } procedure RemoveOldMsiAt(const RootKey: Integer; const RootName: String); var Names: TArrayOfString; I: Integer; SubKey, DisplayName, UninstallString, ProductCode, Params: String; ResultCode: Integer; begin if not RegGetSubkeyNames(RootKey, UninstallKey, Names) then Exit; for I := 0 to GetArrayLength(Names) - 1 do begin SubKey := UninstallKey + '\' + Names[I]; if not RegQueryStringValue(RootKey, SubKey, 'DisplayName', DisplayName) then Continue; if CompareText(DisplayName, AppDisplayName) <> 0 then Continue; if not RegQueryStringValue(RootKey, SubKey, 'UninstallString', UninstallString) then Continue; if Pos('msiexec', LowerCase(UninstallString)) = 0 then Continue; if Copy(Names[I], 1, 1) <> '{' then Continue; ProductCode := Names[I]; Params := '/x ' + ProductCode + ' /qn /norestart'; Log('发现旧 MSI 版:' + RootName + '\' + ProductCode + ',先静默卸载'); Exec('msiexec.exe', Params, '', SW_HIDE, ewWaitUntilTerminated, ResultCode); Log('msiexec 退出码:' + IntToStr(ResultCode)); if ResultCode <> 0 then begin { MSI 卸载失败(现场正是 MSI 坏掉的机器):删掉它的卸载项, 否则以后从「应用和功能」卸载旧 MSI 会把 EXE 版装的文件一起删掉 } if RegDeleteKeyIncludingSubkeys(RootKey, SubKey) then Log('MSI 卸载失败,已移除其卸载项:' + SubKey) else Log('MSI 卸载失败,且移除卸载项失败:' + SubKey); end; end; end; procedure RemoveOldMsi; begin if HasParam('/SKIPMSICLEANUP') then begin Log('跳过旧 MSI 清理(/SKIPMSICLEANUP)'); Exit; end; RemoveOldMsiAt(HKCU, 'HKCU'); RemoveOldMsiAt(HKLM, 'HKLM'); RemoveOldMsiAt(HKLM32, 'HKLM32'); end; procedure CurStepChanged(CurStep: TSetupStep); begin if CurStep = ssInstall then RemoveOldMsi; end;