一 安装包制作
- 准备好可执行的应用程序
- 下载info setup软件 (下载地址:http://www.jrsoftware.org/isdl.php#stable)
- 编辑脚本,生成exe https://www.cnblogs.com/linuxAndMcu/p/10974927.html
二 走过的坑
- 生成 安装程序.exe,双击开始安装 ,但是安装完成后点击界面生成的可执行程序会提示少库, 通过可执行程序找到路径下的原来的可执行程序,双击可以正常运行,查看是因为在安装exe时,会默认在路径下面创建一个exe,(直接把原来的exe拷贝过来),所以在执行应用程序的时候,可执行程序会按照原来的路径依赖关系去查找库,查找不到就会提示找不到库,找不到资源文件。
需要设置运行程序的路径:
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#define MyAppName "Test"
#define MyAppVersion "2020.0115"
#define MyAppPublisher "mycompany.Inc."
#define MyAppURL "http://www.mycompany.com/"
#define MyAppExeName "Tesy.exe"
[Setup]
; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{5DEDA9C7-6A3D-4898-AB9B-5B5BEEC15922}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={autopf}\{#MyAppName}
DisableProgramGroupPage=yes
; The [Icons] "quicklaunchicon" entry uses {userappdata} but its [Tasks] entry has a proper IsAdminInstallMode Check.
UsedUserAreasWarning=no
; Uncomment the following line to run in non administrative install mode (install for current user only.)
;PrivilegesRequired=lowest
OutputDir=D:\output
OutputBaseFilename=Test
SetupIconFile=D:\work\Test\Test\Test.ico
Compression=lzma
SolidCompression=yes
WizardStyle=modern
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; OnlyBelowVersion: 6.1; Check: not IsAdminInstallMode
[Files]
Source: "D:\work\Test\Test.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:\work\Test\bin\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
[Icons]
;注意下面几个app后面的路径, 有时候项目可能有多个文件夹, 这里要注意可执行文件的相对位置对不对,否则可能提示少库
Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\bin\{#MyAppExeName}"
;生成开始菜单卸载
Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}";WorkingDir:"{app}"
;Tasks: desktopicon 上面任务中的,生成快捷方式
Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\bin\{#MyAppExeName}"; Tasks: desktopicon
[Run]
Filename: "{app}\bin\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent
[code]
//卸载时执行
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
if CurUninstallStep = usDone then
begin
//删除 {app} 文件夹及其中所有文件
DelTree(ExpandConstant('{app}'), True, True, True);
//卸载时清除注册表
RegDeleteKeyIncludingSubkeys(HKEY_CURRENT_USER, 'SOFTWARE\myprogram\config')
end;
end;
//初始化时执行
function InitializeSetup(): Boolean;
var
Version: string;
strPath: string;
ResultCode: Integer;
begin
Result:= TRUE;
//read the version
if RegQueryStringValue(HKEY_CURRENT_USER, 'SOFTWARE\myprogram\config',
'Version', Version) then
begin
// Successfully read the value
Version := Format('Exist the version %s,whether uninstall it?',[Version]);
if MsgBox(Version,mbConfirmation,MB_YESNO) = IDYES then
begin
//read the path
if RegQueryStringValue(HKEY_CURRENT_USER, 'SOFTWARE\myprogram\config',
'InstallPath', strPath) then
begin
// Successfully read the value
strPath:= strPath + '\unins000.exe';
Exec(ExpandConstant(strPath), '', '', SW_SHOW,ewWaitUntilTerminated, ResultCode);
end;
end
else
Result:= FALSE;
end;
end;
[Registry]
;将安装路径写入注册表
Root: HKCU; Subkey: "SOFTWARE\myprogram\config"; Flags: createvalueifdoesntexist
Root: HKCU; Subkey: "SOFTWARE\myprogram\config"; Flags: uninsdeletekeyifempty
Root: HKCU; Subkey: "SOFTWARE\myprogram\config"; ValueType: string; ValueName: "InstallPath"; ValueData: "{app}"
Root: HKCU; Subkey: "SOFTWARE\myprogram\config"; ValueType: string; ValueName: "Version"; ValueData: "{#MyAppVersion}"
Root: HKCU; Subkey: "SOFTWARE\myprogram\config"; ValueType: dword; ValueName: "VersionNum"; ValueData: "100"
Root: HKCU; Subkey: "SOFTWARE\myprogram\config"; ValueType: string; ValueName: "Release Date"; ValueData: "2019/12/10"
- win10 安装到最后启动程序时报错:creatprocess failed ,code 740 请求的操作需要提升,但是通过菜单栏和桌面快捷方式运行程序启动正常。测试当exe使用管理员权限启动时不会报错。
修改Inno Setup程序, 使打包的文件以管理员权限运行:
https://blog.csdn.net/u011430225/article/details/84612690
- 安装界面使用中文语言
http://www.80iter.com/blog/1477623891786957
(1)在inno setup 安装目录下面添加中文翻译文件 .isl
(我的查看default.isl时,发现就是中文的,但是安装包是英文的,然后我把default.isl复制了一份,改了名字放到languages目录下面,改了脚本之后成功了。注意如果路径不对,也是使用的默认语言)
(2) 修改脚本语言配置(自己添加的提示语言,直接在脚本中换成中文就可以了)
[Languages]
Name: "Chinese"; MessagesFile: "compiler:Languages\Chinese.isl"
具体脚本:
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
;定义程序相关的信息
#define MyAppName "Test"
#define MyAppVersion "2020.0327"
#define MyAppPublisher "Mycompany.Inc."
#define MyAppURL "http://www.mycompany.com/"
#define MyAppExeName "Test.exe"
[Setup]
; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{5DEDA9C7-6A3D-4898-AB9B-5B5BEEC15922}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={autopf}\{#MyAppName}
DisableProgramGroupPage=yes
; The [Icons] "quicklaunchicon" entry uses {userappdata} but its [Tasks] entry has a proper IsAdminInstallMode Check.
UsedUserAreasWarning=no
; Uncomment the following line to run in non administrative install mode (install for current user only.)
;PrivilegesRequired=lowest
OutputDir=D:\output
OutputBaseFilename=Test
SetupIconFile=D:\work\Test\Test.ico
Compression=lzma
SolidCompression=yes
WizardStyle=modern
[Languages]
Name: "Chinese"; MessagesFile: "compiler:Languages\Chinese.isl"
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; OnlyBelowVersion: 6.1; Check: not IsAdminInstallMode
;exe所在文件夹
[Files]
Source: "D:\work\Test\bin\Test.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:\work\Test\bin\Test\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
[Icons]
Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\bin\{#MyAppExeName}"
;生成开始菜单卸载
Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}";WorkingDir:"{app}"
;Tasks: desktopicon 上面任务中的,生成快捷方式
Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\bin\{#MyAppExeName}"; Tasks: desktopicon
[Run]
Filename: "{app}\bin\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent
[code]
//卸载时执行
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
if CurUninstallStep = usDone then
begin
//删除 {app} 文件夹及其中所有文件
DelTree(ExpandConstant('{app}'), True, True, True);
//卸载时清除注册表
RegDeleteKeyIncludingSubkeys(HKEY_CURRENT_USER, 'SOFTWARE\myprogram\config')
end;
end;
//初始化时执行
function InitializeSetup(): Boolean;
var
Version: string;
strPath: string;
ResultCode: Integer;
begin
Result:= TRUE;
//read the version
if RegQueryStringValue(HKEY_CURRENT_USER, 'SOFTWARE\myprogram\config',
'Version', Version) then
begin
// Successfully read the value
Version := Format('版本 %s 已存在, 是否卸载?',[Version]);
if MsgBox(Version,mbConfirmation,MB_YESNO) = IDYES then
begin
//read the path
if RegQueryStringValue(HKEY_CURRENT_USER, 'SOFTWARE\myprogram\config',
'InstallPath', strPath) then
begin
// Successfully read the value
strPath:= strPath + '\unins000.exe';
Exec(ExpandConstant(strPath), '', '', SW_SHOW,ewWaitUntilTerminated, ResultCode);
end;
end
else
Result:= FALSE;
end;
end;
[Registry]
;将安装路径写入注册表
Root: HKCU; Subkey: "SOFTWARE\myprogram\config"; Flags: createvalueifdoesntexist
Root: HKCU; Subkey: "SOFTWARE\myprogram\config"; Flags: uninsdeletekeyifempty
Root: HKCU; Subkey: "SOFTWARE\myprogram\config"; ValueType: string; ValueName: "InstallPath"; ValueData: "{app}"
Root: HKCU; Subkey: "SOFTWARE\myprogram\config"; ValueType: string; ValueName: "Version"; ValueData: "{#MyAppVersion}"
Root: HKCU; Subkey: "SOFTWARE\myprogram\config"; ValueType: dword; ValueName: "VersionNum"; ValueData: "100"
Root: HKCU; Subkey: "SOFTWARE\myprogram\config"; ValueType: string; ValueName: "Release Date"; ValueData: "2019/12/10"
- 最近换了系统,然后又莫名奇妙出了个问题,权限的问题又出了
之前用的win7,加了固态,装了win10系统,在win10系统上, C盘安装了inno setup软件,参照前面的方案修改了,然后运行的时候老是提示 无法修改 con.ini文件到C盘, 然后就用管理员权限运行, 发现这个报错没有了, 然而编译生成的可执行文件老是报2 的错误一下子懵了,什么情况?之前的2的方案有问题?又找到之前win7安装的inno setup,之前安在D盘, 打开运行,发现可以了。 测试把D盘中的软件以管理员权限运行,生成的也是可以的,所以在安装的时候报 无法修改 con.ini文件到C盘 这个错是不是有什么影响,并且以管理员权限运行的时候也没有修复 ?
(搜索材料的时候依赖了很多前辈的经验,感谢!)