• 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







  • 相关阅读:
    Spring第三天:Spring的AOP的注解开发、Spring的声明式事务、JdbcTemplate
    Spring第二天:Spring的IOC的注解方式、Spring的AOP开发(XML)
    Spring第一天:Spring的概述、SpringIOC入门(XML)、Spring的Bean管理、Spring属性注入
    PHP变量的声明及其作用域
    p {font-family: "sans serif";}
    深入理解JavaScript位运算符
    Jquery ajax 解析加载XML文件
    php网站开发安全小常识
    简单的DOS攻击之死亡之ping详解
    php中GET和POST的区别
  • 原文地址:https://www.cnblogs.com/whosedream/p/2294224.html
Copyright © 2020-2023  润新知