目錄
一、前言
InnoSetup 是一個免費的 Windows 安裝程序製作軟件,簡單的說,就是打包程序給用戶安裝。
二、效果展示
...
三、教程&源碼
1. 打開編輯器,Inno Setup 5\Inno Setup 5\Compil32.exe
2. 編輯器->文件->打開,打開Inno Setup 5\setup.iss,可看到代碼如下
; 腳本由 Inno Setup 腳本嚮導 生成!
; 有關創建 Inno Setup 腳本文件的詳細資料請查閱幫助文檔!
#define MyAppName "CTest1"
#define APP_FOLDER_NAME "CTest1"
#define MyAppPublisher "YJJ"
#define MyAppDate "2020-04-21"
#define MyAppURL "https://www.stu.edu.cn/"
#define MyAppExeName "CTest1.exe"
#define VERSION_MAJOR 1
#define VERSION_MINOR 0
#define VERSION_SUBVRN 0
#define VERSION_REVISION 1
#define VERSION_SETUP "setup"
[Setup]
; 注: AppId的值爲單獨標識該應用程序。
; 不要爲其他安裝程序使用相同的AppId值。
; (生成新的GUID,打開Inno Setup 5\Inno Setup 5\Compil32.exe 工具|在IDE中生成GUID。)
AppId={{7380C08E-B23A-4857-9423-F83C12415562}
;應用程序名稱
AppName={#MyAppName}
;應用程序版本
AppVersion={#VERSION_MAJOR}.{#VERSION_MINOR}.{#VERSION_SUBVRN}.{#VERSION_REVISION}
;發佈者信息
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#APP_FOLDER_NAME}
;創建開始菜單快捷方式文件夾名稱
DefaultGroupName={#MyAppName}
AllowNoIcons=yes
InfoBeforeFile=Readme.txt
;程序安裝包輸出路徑
OutputDir=./
;安裝和應用圖標
SetupIconFile=./main.ico
WizardImageFile=./wizard.bmp
WizardSmallImageFile=./small.bmp
Compression=lzma
SolidCompression=yes
;程序安裝包輸出名稱
OutputBaseFilename={#MyAppName}{#VERSION_MAJOR}.{#VERSION_MINOR}.{#VERSION_SUBVRN}.{#VERSION_REVISION}{#VERSION_SETUP}
ShowUndisplayableLanguages = yes
[Languages]
Name: "english"; MessagesFile: "compiler:Default.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: "italian"; MessagesFile: "compiler:Languages\Italian.isl"
Name: "japanese"; MessagesFile: "compiler:Languages\Japanese.isl"
Name: "spanish"; MessagesFile: "compiler:Languages\Spanish.isl"
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: checkablealone;
[Files]
;製作安裝包的主執行文件所在位置
Source: "..\CTest1\CTest1.exe"; DestDir:"{app}"; Flags:ignoreversion
;製作安裝包的目錄文件夾所在位置
Source: "..\CTest1\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; 注意: 不要在任何共享系統文件上使用“Flags: ignoreversion”
[Icons]
;開始菜單快捷方式主程序名稱
Name: "{group}\{#MyAppName}"; Filename: "{app}/{#MyAppExeName}"
;開始菜單快捷方式卸載名稱
Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}"
;桌面快捷方式名稱
Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}/{#MyAppExeName}"; Tasks: desktopicon; WorkingDir: "{app}"
[Run]
;安裝完畢後提示是否運行的項目名稱
Filename: "{app}/{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent
代碼比較簡單,可自行閱覽。
如果需要改圖標,還需自行替換文件main.ico,small.bmp,wizard.bmp,這裏值得注意的是,請在網上使用工具轉換爲相關的文件,不能自行改後綴,否則格式不符合會報錯。
例如本機是small.jpg文件,自行修改名稱爲small.bmp,編譯後運行會找不到圖片報錯。
修改完畢後,點擊菜單欄編譯圖標,即可在文件夾生成相關安裝包
這就是打包後的安裝包。
四、Demo/相關包
另附Inno Setup5軟件和Demo供大家參考(百度雲盤):
鏈接:https://pan.baidu.com/s/15qk40VjVoBJVSMa8pfZHfg
提取碼:89y9