innoSetup打包文件編寫模板(二):支持覆蓋安裝,安裝前關閉運行,避免安裝失敗
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


浙公網安備 33010602011771號