1.支持重复安装
2.安装前关闭程序,避免覆盖失败
3.卸载前关闭程序,避免卸载失败
重点:使用终端命名杀死进程
ShellExec('open', ExpandConstant('{cmd}'), '/c taskkill /f /t /im hp.exe', '', SW_HIDE, ewNoWait, ErrorCode);
; 自定义的宏,方便后期维护 #define MyAppName "HP DocCam" #define MyAppVersion "V1.0" #define MyAppExeName "hp.exe" #define MyAppPublisher "HP DocCam Huyang" [Setup] AppId={{F382DAB1-E185-41EF-B6ED-32E86CC310HU-HP-DocCam} AppName={#MyAppName} AppVersion={#MyAppVersion} ;AppVerName={#MyAppName} {#MyAppVersion} ; 发布者 - 安装包文件版本 - 版权 AppPublisher={#MyAppPublisher} VersionInfoVersion=1.0 VersionInfoCopyright={#MyAppPublisher} ; 默认安装文件夹路径 ;DefaultDirName={pf}\{#MyAppName} DefaultDirName={commonpf64}\{#MyAppName} ; 默认组名称,开始菜单中会用到这个名称 DefaultGroupName={#MyAppName} DisableProgramGroupPage=yes ; 打包后安装包的保存路径 - 打包后安装包的名称 OutputDir=output OutputBaseFilename={#MyAppName} {#MyAppVersion}-d Compression=lzma SolidCompression=yes ; 允许重复安装 UsePreviousAppDir=yes ; 安装包图标 & 卸载程序图标 SetupIconFile = Release\logo.ico UninstallIconFile = Release\logo.ico ; 控制面板 UninstallDisplayIcon = {app}\logo.ico Uninstallable=yes UninstallDisplayName={#MyAppName} ; 签名 ;SignTool=sha1 ;SignTool=sha256 [Languages] Name: "English"; MessagesFile: "compiler:Languages\English.isl" Name: "chinesesimp"; MessagesFile: "compiler:Languages\ChineseSimp.isl" Name: "ChineseTrad"; MessagesFile: "compiler:Languages\ChineseTrad.isl" Name: "French"; MessagesFile: "compiler:Languages\French.isl" Name: "German"; MessagesFile: "compiler:Languages\German.isl" Name: "Spanish"; MessagesFile: "compiler:Languages\Spanish.isl" Name: "Portuguese"; MessagesFile: "compiler:Languages\Portuguese.isl" Name: "Russian"; MessagesFile: "compiler:Languages\Russian.isl" Name: "Italian"; MessagesFile: "compiler:Languages\Italian.isl" Name: "Greek"; MessagesFile: "compiler:Languages\Greek.isl" Name: "Japanese"; MessagesFile: "compiler:Languages\Japanese.isl" Name: "Korean"; MessagesFile: "compiler:Languages\Korean.isl" [Tasks] ;Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: checkablealone [Files] ; exe Source: "Release\hp.exe"; DestDir: "{app}"; Flags: ignoreversion ; flt & ini Source: "Release\video.flt"; DestDir: "{app}"; Flags: ignoreversion ; 图标 Source: "Release\logo.ico"; DestDir: "{app}"; Flags: ignoreversion Source: "Release\logo.png"; DestDir: "{app}"; Flags: ignoreversion ; dll Source: "Release\*.dll"; DestDir: "{app}"; Flags: ignoreversion ; 文件夹 Source: "Release\iconengines\*"; DestDir: "{app}\iconengines"; Flags: ignoreversion recursesubdirs createallsubdirs Source: "Release\imageformats\*"; DestDir: "{app}\imageformats"; Flags: ignoreversion recursesubdirs createallsubdirs Source: "Release\platforms\*"; DestDir: "{app}\platforms"; Flags: ignoreversion recursesubdirs createallsubdirs Source: "Release\styles\*"; DestDir: "{app}\styles"; Flags: ignoreversion recursesubdirs createallsubdirs [INI] ;良田版,中文,不打开控制台 Filename: "{userappdata}\Eloam\Cfg\lib.ini"; Section: "EL";Key: "consoleLevel"; String: "0" ; [Registry] Root: HKLM; Subkey: Software\VisualPresent; ValueType: string; ValueName: huyangHPDocCam; ValueData: '123456'; Flags: uninsdeletekey ; 解决重复安装 [code] // 根据用户选择的语言,设置软件配置文件,用来显示对应的语言 procedure CurStepChanged(CurStep: TSetupStep); var languageName: string; begin if CurStep=ssDone then //软件安装后执行 begin languageName := ActiveLanguage(); // 获取用户选择的语言 if 'chinesesimp' = languageName then begin SetIniString('dev','softwarelanguage','0',ExpandConstant('{app}\conf.ini')); end else if 'ChineseTrad' = languageName then begin SetIniString('dev','softwarelanguage','1',ExpandConstant('{app}\conf.ini')); end else if 'English' = languageName then begin SetIniString('dev','softwarelanguage','2',ExpandConstant('{app}\conf.ini')); end else if 'French' = languageName then begin SetIniString('dev','softwarelanguage','3',ExpandConstant('{app}\conf.ini')); end else if 'German' = languageName then begin SetIniString('dev','softwarelanguage','4',ExpandConstant('{app}\conf.ini')); end else if 'Spanish' = languageName then begin SetIniString('dev','softwarelanguage','5',ExpandConstant('{app}\conf.ini')); end else if 'Portuguese' = languageName then begin SetIniString('dev','softwarelanguage','6',ExpandConstant('{app}\conf.ini')); end else if 'Russian' = languageName then begin SetIniString('dev','softwarelanguage','7',ExpandConstant('{app}\conf.ini')); end else if 'Italian' = languageName then begin SetIniString('dev','softwarelanguage','8',ExpandConstant('{app}\conf.ini')); end else if 'Greek' = languageName then begin SetIniString('dev','softwarelanguage','9',ExpandConstant('{app}\conf.ini')); end else if 'Japanese' = languageName then begin SetIniString('dev','softwarelanguage','10',ExpandConstant('{app}\conf.ini')); end else if 'Korean' = languageName then begin SetIniString('dev','softwarelanguage','11',ExpandConstant('{app}\conf.ini')); end; end; end; // 安装前检查软件是否正在运行, function InitializeSetup(): Boolean; var ErrorCode: Integer; begin ShellExec('open', ExpandConstant('{cmd}'), '/c taskkill /f /t /im hp.exe', '', SW_HIDE, ewNoWait, ErrorCode); Result := True; end; // 卸载前检查软件是否正在运行 function InitializeUninstall(): Boolean; var ErrorCode: Integer; begin ShellExec('open', ExpandConstant('{cmd}'), '/c taskkill /f /t /im hp.exe', '', SW_HIDE, ewNoWait, ErrorCode); Result := True; end; [Icons] Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; IconFilename: "{app}\logo.ico" Name: "{group}\{cm:UninstallProgram, {#MyAppName}}"; Filename: "{uninstallexe}" Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; IconFilename:"{app}\logo.ico" [Run] Filename: "{app}\MJPGDriver.exe"; Parameters: "/verysilent /norestart"; Description: "{cm:LaunchProgram, MJPGDriver}"; Flags:postinstall waituntilterminated skipifsilent ;Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent
标签:begin,end,Name,app,innoSetup,languageName,ExpandConstant,安装,模板 From: https://www.cnblogs.com/shiyixirui/p/18637687