InnoSetup 腳本打包及管理員權限設置

InnoSetup使用教程:InnoSetup打包安裝html

腳本詳細

1. 定義變量

1 #define MyAppName "TranslationTool"
2 #define MyAppChineseName "翻譯工具"
3 #define MyAppVersion "1.0"
4 #define MyAppPublisher "dotnetschool"
5 #define MyAppURL "https://dotnet-campus.github.io/"
6 #define MyAppExeName "TranslationTool.exe"

2. 初始化安裝包設置

 1 [Setup]
 2 ; NOTE: The value of AppId uniquely identifies this application.
 3 ; Do not use the same AppId value in installers for other applications.
 4 ; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
 5 AppId={{AEDA7675-70DC-479E-B796-344517C2C954}
 6 AppName={#MyAppName}
 7 AppVersion={#MyAppVersion}
 8 ;AppVerName={#MyAppName} {#MyAppVersion}
 9 AppPublisher={#MyAppPublisher}
10 AppPublisherURL={#MyAppURL}
11 AppSupportURL={#MyAppURL}
12 AppUpdatesURL={#MyAppURL}
13 DefaultDirName={pf}\{#MyAppName}
14 DefaultGroupName={#MyAppChineseName}
15 OutputDir=C:\Users\10167\Desktop
16 OutputBaseFilename={#MyAppChineseName}
17 SetupIconFile=F:\GitHub\TranslationApiDemo\TranslationTool\TranslationTool\Images\bitbug_favicon.ico
18 Compression=lzma
19 SolidCompression=yes

其中,git

  • AppId 程序標識
  • AppName 程序名稱
  • AppVersion 版本號。生成默認版本號AppName+AppVersion
  • AppVerName 程序版本號。若是設置了AppVersion,則AppVerName會覆蓋AppVersion值。
  • AppPublisher 發佈者
  • AppPublisherURL、AppSupportURL、AppUpdatesURL 相關連接
  • DefaultDirName 默認安裝目錄
  • DefaultGroupName 默認開始菜單目錄名
  • OutputDir 打包exe的生成目錄,好比能夠設置在桌面
  • OutputBaseFilename 打包exe的文件名稱
  • SetupIconFile 設置打包exe的圖標
  • Compression、SolidCompression 壓縮相關

3. 啓動文件和程序全部文件

1 [Files]
2 Source: "F:\GitHub\TranslationApiDemo\TranslationTool\TranslationTool\bin\Debug\TranslationTool.exe"; DestDir: "{app}"; Flags: ignoreversion
3 Source: "F:\GitHub\TranslationApiDemo\TranslationTool\TranslationTool\bin\Debug\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
4 ; NOTE: Don't use "Flags: ignoreversion" on any shared system files

4. 圖標

1 [Icons]
2 Name: "{group}\{#MyAppChineseName}"; Filename: "{app}\{#MyAppExeName}"
3 Name: "{group}\{cm:UninstallProgram,{#MyAppChineseName}}"; Filename: "{uninstallexe}"
4 Name: "{commondesktop}\{#MyAppChineseName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon

從上而下,分別是開始菜單中的啓動快捷方式、開始菜單中的卸載快捷方式、桌面快捷方式github

5. 直接啓動

1 [Run]
2 Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#MyAppChineseName}}";Flags: nowait postinstall skipifsilent

在完成安裝後,能夠選擇直接啓動。app

6. 添加Pascal代碼

以上都只是innosetup提供的配置,若是須要定製註冊表、卸載其它軟件、定製界面、用戶環境等,能夠經過innosetup提供的一些事件來處理。如:ide

1 [code]
2 function InitializeSetup (): Boolean; 
3 begin
4    MsgBox('程序安裝!', mbInformation, MB_OK);
5    Result := true;     
6 end; 

 

此處只介紹一些經常使用的字段參數,詳細的可參考其它博客:https://blog.csdn.net/yiyihuazi/article/details/60323746http://www.javashuo.com/article/p-gapdfbni-ec.html工具

案例腳本:post

 1 ; Script generated by the Inno Setup Script Wizard.
 2 ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
 3 
 4 #define MyAppName "TranslationTool"
 5 #define MyAppChineseName "翻譯工具"
 6 #define MyAppVersion "1.0"
 7 #define MyAppPublisher "dotnetschool"
 8 #define MyAppURL "https://dotnet-campus.github.io/"
 9 #define MyAppExeName "TranslationTool.exe"
10 
11 [Setup]
12 ; NOTE: The value of AppId uniquely identifies this application.
13 ; Do not use the same AppId value in installers for other applications.
14 ; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
15 AppId={{AEDA7675-70DC-479E-B796-344517C2C954}
16 AppName={#MyAppName}
17 AppVersion={#MyAppVersion}
18 ;AppVerName={#MyAppName} {#MyAppVersion}
19 AppPublisher={#MyAppPublisher}
20 AppPublisherURL={#MyAppURL}
21 AppSupportURL={#MyAppURL}
22 AppUpdatesURL={#MyAppURL}
23 DefaultDirName={pf}\{#MyAppName}
24 DefaultGroupName={#MyAppChineseName}
25 OutputDir=C:\Users\10167\Desktop
26 OutputBaseFilename={#MyAppChineseName}
27 SetupIconFile=F:\GitHub\TranslationApiDemo\TranslationTool\TranslationTool\Images\bitbug_favicon.ico
28 Compression=lzma
29 SolidCompression=yes
30 
31 [Languages]
32 Name: "english"; MessagesFile: "compiler:Default.isl"
33 
34 [Tasks]
35 Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
36 
37 [Files]
38 Source: "F:\GitHub\TranslationApiDemo\TranslationTool\TranslationTool\bin\Debug\TranslationTool.exe"; DestDir: "{app}"; Flags: ignoreversion
39 Source: "F:\GitHub\TranslationApiDemo\TranslationTool\TranslationTool\bin\Debug\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
40 ; NOTE: Don't use "Flags: ignoreversion" on any shared system files
41 
42 [Icons]
43 Name: "{group}\{#MyAppChineseName}"; Filename: "{app}\{#MyAppExeName}"
44 Name: "{group}\{cm:UninstallProgram,{#MyAppChineseName}}"; Filename: "{uninstallexe}"
45 Name: "{commondesktop}\{#MyAppChineseName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
46 
47 [Run]
48 Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#MyAppChineseName}}";Flags: nowait postinstall skipifsilent
View Code

 

 設置安裝包以管理員權限運行

若是安裝包須要以管理員運行,在VS中設置程序以管理員權限啓動以後,this

在InnoSetup安裝目錄下,找到配置SetupLdr.e32文件,設置Manifest中的權限啓動參數(與VisualStudio相似),操做以下:spa

下載Resource Hacker編譯器,而後打開.e32文件,將其中權限相關參數,修改成管理員權限。.net

詳細操做可參考:用inno setup製做管理員權限啓動的安裝包

案例截圖

生成的安裝包exe以及安裝後桌面快捷方式

開始菜單中的快捷方式

相關文章
相關標籤/搜索