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


InnoSetup使用教程:InnoSetup打包安裝

腳本詳細

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

其中,

  • 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

忽略文件 Excludes: "*.bak,*.pdb,*.dll.config,*.ax,*\Log\*";

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

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

5. 直接啟動

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

在完成安裝后,可以選擇直接啟動。

6. 添加Pascal代碼

以上都只是innosetup提供的配置,如果需要定制注冊表、卸載其它軟件、定制界面、用戶環境等,可以通過innosetup提供的一些事件來處理。如:

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/60323746https://www.cnblogs.com/langtianya/p/4285570.html

案例腳本:

 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中設置程序以管理員權限啟動之后,

在InnoSetup安裝目錄下,找到配置SetupLdr.e32文件,設置Manifest中的權限啟動參數(與VisualStudio類似),操作如下:

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

詳細操作可參考:用inno setup制作管理員權限啟動的安裝包

案例截圖

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

開始菜單中的快捷方式


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM