ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

Inno Setup制作安装程序

2022-02-24 11:58:20  阅读:299  来源: 互联网

标签:Setup ISSkin MyAppName 安装程序 Flags Inno app


转自:Inno Setup制作安装程序 - 一文钱 - 博客园

Inno Setup 是国外的一个打包工具,很小巧,功能很强大。

Step 1

我们可以用向导模式,先生成一个简单的脚本,如果觉得这样就够了,那么也可以了,呵呵。

按着向导一步一步做

#define MyAppName "我的程序"
#define MyAppVersion "1.5"
#define MyAppPublisher "我的公司"
#define MyAppURL "http://www.example.com/"
#define MyAppExeName "Test.exe"

[Setup]
;这个段包含用于安装程序和卸载程序的全局设置。某些提示对于你创建的任何安装程序都是必需的。
; 注: AppId的值为单独标识该应用程序
; 不要为其他安装程序使用相同的AppId 
AppId={{CA36259E-42E5-469E-BD8B-70EE1FDF2CFB}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName={#MyAppName}
LicenseFile=E:\Lisence.rtf
OutputBaseFilename=setup
Compression=lzma
SolidCompression=yes

[Languages]
;Inno Setup 支持多语言安装。[Languages] 段用来定义安装程序中可使用的语言。
Name: "chinesesimp"; MessagesFile: "compiler:Default.isl"

[Tasks]
;这个段是只选的。它定义安装程序在执行安装期间所有由用户定制的任务。这些任务以选项框和单选项形式在附加任务向导页中出现。
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; OnlyBelowVersion: 0,6.1

[Files]
;这是定义安装程序安装文件到用户系统中的可选文件段。
Source: "D:\zm\TY\Test.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:\zm\TY\Debug\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; 注意:不要在任何共享文件系统上使用 Flags: ignoreversion

[Icons]
;这个可选段定义所有创建在开始菜单和/或其它位置 (比如桌面) 的快捷方式。
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon

[Run]
;[Run] 段是可选的,用来指定程序完成安装后、在安装程序显示最终对话框之前要执行的程序数,
;[UninstallRun] 段也可样是可选的,用来指定在卸载第一步要执行的程序数。除在下面有注释的外,两个段用相同的语法。
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, "&", "&&")}}"; Flags: nowait postinstall skipifsilent
我们可以添加点参数,来改变改变安装界面
[Setup]
WindowVisible=yes

效果还是蛮不错的。

有时候我们想在安装程序执行前,或者执行后做些事情,比如往一个文件里写入某些东西。

[Files]
Source: "E:\Debug\systy.ini"; DestDir: "{commonappdata}"; Flags: onlyifdoesntexist uninsneveruninstall;AfterInstall:MyAfterInstall 
onlyifdoesntexist :仅在用户系统中不存在时安装文件。
uninsneveruninstall:该文件将在卸载时不被删除,但涉及的计数仍将正确减少。
当加入上面这段代码后,安装文件安装完systy.ini后,就会执行MyAfterInstall方法。

[Code]
procedure MyAfterInstall();
var Path: string;
var FindRec: TFindRec;
var Date: string ;
var Encrypt:string;
 
begin
  Path:=ExpandConstant('{commonappdata}')+'\systy.ini';
  Date:=GetDateTimeString('yyyy/mm/dd hh:nn:ss', '-', ':');
   
  Encrypt:=Uppercase(GetMD5OfString(Date));
  

  try
  SaveStringToFile(Path, Date+#13#10+Encrypt, false);
  ;我们可以向这文件里写入日期和一段加密的字符串,呵呵
  except
    // 捕获异常,用它进行处理,并继续
    MsgBox('我们监视到这个异常:' + AddPeriod(GetExceptionMessage),
      mbError, MB_OK);
  end;
 
end;
如果想让安装程序来点风格,那么可以用ISSkin.DLL

office2007的风格还是蛮清新的,更多的风格可以去这里看看,我很奇怪汉化版为啥加载不了这些皮肤,呵呵,谁知道的,告知一下

[code]
// Importing LoadSkin API from ISSkin.DLL
procedure LoadSkin(lpszPath: String; lpszIniFileName: String);
external 'LoadSkin@files:isskin.dll stdcall';

// Importing UnloadSkin API from ISSkin.DLL
procedure UnloadSkin();
external 'UnloadSkin@files:isskin.dll stdcall';

// Importing ShowWindow Windows API from User32.DLL
function ShowWindow(hWnd: Integer; uType: Integer): Integer;
external 'ShowWindow@user32.dll stdcall';

function InitializeSetup(): Boolean;
begin
  ExtractTemporaryFile('Office2007.cjstyles');
  //MsgBox(ExpandConstant('{tmp}\Office2007.cjstyles'), mbInformation, MB_OK);
  LoadSkin(ExpandConstant('{tmp}\Office2007.cjstyles'), 'NormalBlack.ini');
  Result := True;
end; 
procedure DeinitializeSetup();
begin
  // Hide Window before unloading skin so user does not get
  // a glimpse of an unskinned window before it is closed.
  ShowWindow(StrToInt(ExpandConstant('{wizardhwnd}')), 0);
  UnloadSkin();
end; 

[Files]
; Add the ISSkin DLL used for skinning Inno Setup installations.
Source: "E:\Debug\ISSkin.dll"; DestDir: {app}; Flags: dontcopy

; Add the Visual Style resource contains resources used for skinning,
; you can also use Microsoft Visual Styles (*.msstyles) resources.
Source: "E:\bin\Debug\Office2007.cjstyles"; DestDir: {tmp}; Flags: dontcopy 


 


 


 

标签:Setup,ISSkin,MyAppName,安装程序,Flags,Inno,app
来源: https://blog.csdn.net/qqwangfan/article/details/123108444

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有