Inno step使用

Inno step 打包 归档 EXE文件

Posted by gomyck on June 26, 2019

windows安装程序制作工具使用

—-起因—-

因公司业务需要把java服务傻瓜式安装到客户机, 个人认为解决起来有如下方案(欢迎右下角留言补充, 需要github账号登录):

1.远程安装, 因网络环境因素被 pass

2.虚拟机, 镜像太笨重, 配置繁琐, 且需要先安装虚拟机 pass

3.docker, 需要docker进程支持, 而且windows版的docker对windows的版本有兼容问题 pass

4.像安装qq似的安装, 可行 (需要的知识点: mysql的zip版配置 windows服务的注册 简单脚本的编写 打包程序的学习)

—-准备工作—-

1.下载工具 inno step 中文版

inno step可以制作多种windows版本的安装包程序, 标准的安装向导样式

2.下载C文件修改工具:reshacker 这个文件是用来修改inno step的源文件, 因为inno step打包出来的exe不能自动申请admin权限

3.安装好inno step之后, 在开始菜单内, 找到inno setup可执行文件, 使用新建向导创建一个配置文件

4.下载.net环境包以及cpp环境包(可选, 如果需要在低版本windows中运行mysql或其他c程序, 可能会跑不起来, 需要这两个环境的支持)

—-配置篇—-

具体的文件夹目录以及层级请看下面的配置吧, 看file和run的配置建立对应的文件夹结构即可

1
2
3
4
core下放的是mysql和jre
resources下是java服务(jar包)
script下是脚本文件
dependence下是.net和cpp的安装包
整理的inno step配置文件:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#define MyAppName "应用名称"
#define MyAppVersion "1.0.0-release"
#define MyAppPublisher "gomyck/haoy"
#define MyAppURL "https://www.gomyck.com/"
#define MyAppExeName "应用名字.exe"
#define InstallPath "c:/gomyck"

[Setup]
AppId={346EB827-B34C-441D-A32A-F9865A4B3A22}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={#InstallPath}
DefaultGroupName={#MyAppName}
OutputBaseFilename={#MyAppName}
SetupIconFile={#InstallPath}/resources/icon/gomyck.ico
Compression=lzma
SolidCompression=yes
PrivilegesRequired=admin
;DisableDirPage属性在生产过程中写成yes
DisableDirPage=yes

[Languages]
Name: "chinesesimp"; MessagesFile: "compiler:Default.isl"

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; OnlyBelowVersion: 0,6.1

[Files]
Source: "C:\gomyck\core\*"; DestDir: "{app}\core"; Flags: ignoreversion
Source: "C:\gomyck\script\*"; DestDir: "{app}\script"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "C:\gomyck\resources\*"; DestDir: "{app}\resources"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "C:\gomyck\dependence\*"; DestDir: "{app}\dependence"; Flags: ignoreversion recursesubdirs createallsubdirs
; recursesubdirs: 打包下面的子文件夹    createallsubdirs: 安装时同步安装子文件夹

[Types]
Name: "full"; Description: "完全安装"
Name: "custom"; Description: "自定义安装"; Flags: iscustom

[Components]
Name: "main"; Description: "主文件"; Types: full custom; Flags: fixed
Name: "vcredist_x64"; Description: "Visual C++ 2013(x64)"; Types: full;
Name: "dotnet"; Description: ".Net framework4.0"; Types: full;


[Icons]
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; IconFilename: "{app}\init\gomyck.ico"
Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; IconFilename: "{app}\init\gomyck.ico"; Tasks: desktopicon

[Run]
Filename: "{app}\dependence\vcredist_x64.exe"; Components: vcredist_x64;
Filename: "{app}\script\init\initDotnet.bat"; Components: dotnet;
Filename: "{app}\script\init\initMysql.bat"; Flags: runhidden;
Filename: "{app}\script\init\initServer.bat"; Flags: runhidden;

[UninstallRun]
Filename: "{app}\script\uninstall\uninstallMysql.bat"; Flags: runhidden;
Filename: "{app}\script\uninstall\uninstallServer.bat"; Flags: runhidden;

针对配置文件里面的属性做一下说明:

#define xxx “demoDefine” 声明一个全局变量, 可以使用{xxx} 来引用

[setup] 安装信息, 看字面意思应该能看出来是啥
1
2
3
4
Compression=lzma   压缩方式
SolidCompression=yes   是否使用压缩
PrivilegesRequired=admin   是否在安装时申请admin权限
DisableDirPage=yes  是否显示安装路径  这个在生产过程中写成yes
[Files] 需要安装的文件(一定会安装)
1
2
Source: "C:\holystar\dependence\*"; DestDir: "{app}\dependence"; Flags: ignoreversion recursesubdirs createallsubdirs
Source是资源文件路径, destDir是安装时的目标路径, flags的意思分别为: 忽略文件版本 把子文件夹也打包 安装时同步创建子文件夹
[Type] 安装类型
1
2
Name: "custom"; Description: "自定义安装"; Flags: iscustom
名字(标签)为自定义安装, 注释为: 自定义安装, 标志: 自定义
[Components] 和Type组合使用
1
2
Name: "main"; Description: "主文件"; Types: full custom; Flags: fixed
名字(标签)叫main,  注释为:主文件, 类型为: 全量安装和自定义安装, Flags: fixed  不可勾选
[Run] 在安装后, 需要运行的一些东西(run需要和type和components组合使用)
1
2
Filename: "{app}\dependence\vcredist_x64.exe"; Components: vcredist_x64;
{app} 指的是安装路径   Components: vcredist_x64   当有name=vcredist_x64的组件在安装的时候被勾选时, 才运行这个脚本||程序
[UninstallRun] 卸载时运行的脚本
1
2
Filename: "{app}\script\uninstall\uninstallMysql.bat"; Flags: runhidden;
Flags: runhidden 安装时为静默安装

—-脚本篇—-:

这个脚本里面有生成windows服务的插件, 默认需要.net环境 其他命令看一下每个脚本里写的就明白了

.net环境安装(需要.net安装包)
1
2
3
4
5
6
7
8
#initDotnet.bat
$ echo off
$ cd %~dp0
$ cd ..
$ cd ..
$ cd dependence
$ dotnet4.0.exe /q:a /c:"install /l /q"
$ exit
mysql数据库安装并注册成服务并自启动
1
2
3
4
5
6
7
8
9
10
11
#initMysql.bat
$ echo off
$ cd %~dp0
$ cd ..
$ cd ..
$ cd dependence
$ cd mysql
$ cd bin
$ mysqld.exe --install mysql5.7_gomyck
$ net start mysql5.7_gomyck
$ exit
java服务注册成windows服务并自启动(这里需要一个exe插件, 就不上传了, 需要的可以Q我)
1
2
3
4
5
6
#initServer.bat
$ echo off
$ cd %~dp0
$ initServiceStarter.exe install
$ net start ssh-gomyck
$ exit
卸载mysql服务
1
2
3
4
5
6
7
8
9
10
11
#uninstallMysql.bat
$ echo off
$ cd %~dp0
$ cd ..
$ cd ..
$ cd dependence
$ cd mysql
$ cd bin
$ net stop mysql5.7_gomyck
$ mysqld.exe --remove mysql5.7_gomyck
$ exit
卸载java服务
1
2
3
4
5
6
7
8
#uninstallServer.bat
$ echo off
$ cd %~dp0
$ cd ..
$ cd init
$ net stop ssh-gomyck
$ initServiceStarter.exe uninstall
$ exit
windows dos下的一些变量:
1
2
3
4
5
6
$ echo 当前盘符: %~d0
$ echo 当前盘符和路径: %~dp0
$ echo 当前批处理全路径: %~f0
$ echo 当前盘符和路径的短文件名格式: %~sdp0
$ echo 当前CMD默认目录: %cd%
$ pause
Inno step安装的文件无法获取admin权限问题解决:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
首先,
在[Setup]段加入
PrivilegesRequired=admin

然后用下载的软件reshacker :
找到inno setup安装目录下的SetupLdr.e32文件,将程序中的Manifest更改一下(用reshacker这类工具改),
这样运行程序的时候Windows Vista / windows 7 就会自动提示需要管理员权限

--- 改造如下:
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
改为
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
这样运行时提示需要安装员权限。
以后所有被编译出的安装程序都会自都要求管理员权限。