zoukankan      html  css  js  c++  java
  • [转载]INNO Setup 使用笔记

    http://www.cnblogs.com/pyw0818/archive/2011/01/22/1941806.html (自定义卸载)

    http://www.cnblogs.com/pyw0818/archive/2011/01/22/1941795.html

    http://www.cnblogs.com/pyw0818/archive/2011/01/22/1941799.html

    http://www.cnblogs.com/pyw0818/archive/2011/01/22/1941963.html

    http://www.cnblogs.com/pyw0818/archive/2011/01/22/1941797.html

    INNO Setup 使用笔记

    [Setup]

    AppName={#MyAppName}

    AppVerName={#MyAppVerName}

    AppPublisher={#MyAppPublisher}

    AppPublisherURL={#MyAppURL}

    AppSupportURL={#MyAppURL}

    AppUpdatesURL={#MyAppURL}

    DefaultDirName={pf}/My Programee

    DefaultGroupName={#MyAppName}

    InfoBeforeFile=D:/Inno Setup 5/Examples/Readme.txt 安装前的查看信息

    InfoAfterFile=D:/Inno Setup 5/Examples/Readme-German.txt 安装后的查看信息

    OutputBaseFilename=setup

    Compression=lzma

    SolidCompression=yes

    [Run]

    安装结束后要运行的选项

    Filename: "{app}/MyProg.EXE"

    (直接运行不提示,没有可选)

    [Icons](快捷方式)

    Name: "{commonprograms}/My Program"; Filename: "{app}/MyProg.exe"

    (在程序的快捷方式)

    Name: "{userdesktop}/My Program"; Filename: "{app}/MyProg.exe"

    (在桌面快捷方式)

    Name: "{group}/My Program"; Filename: "{app}/MyProg.exe"

    ({group}/My Program 快捷方式名 后面是对应的程序 )

    Commonprograms 程序菜单

    Userdesktop 桌面

    Group程序菜单的文件夹里

    [Files]

    Source: "MyProg.exe"; DestDir: "{app}"

    Source: "MyProg.hlp"; DestDir: "{app}"; Flags: isreadme

    ( Flags: isreadme 安装结束后要读的选项)

    Source: "Readme.txt"; DestDir: "{app}"; Flags: isreadme
    Source: MyDll.dll; DestDir: {app}; Flags: ignoreversion; (调用自定义的函数)


    [Registry] 注册表内容

    Root: HKCU; Subkey: "Software/My Company"; Flags: uninsdeletekeyifempty

    Root: HKCU; Subkey: "Software/My Company/My Program"; Flags: uninsdeletekey

    Root: HKCU; Subkey: "Software/My Company/My Program/Settings"; ValueType: string; ValueName: "Name"; ValueData: "{code:GetUser|Name}"

    Root: HKCU; Subkey: "Software/My Company/My Program/Settings"; ValueType: string; ValueName: "Company"; ValueData: "{code:GetUser|Company}"

    Root: HKCU; Subkey: "Software/My Company/My Program/Settings"; ValueType: string; ValueName: "DataDir"; ValueData: "{code:GetDataDir}"

    [code] 自定义安装界面 不区分大小写

    [Setup]

    AppName=My Program

    AppVerName=My Program version 1.5

    CreateAppDir=no

    DisableProgramGroupPage=yes

    DefaultGroupName=My Program

    UninstallDisplayIcon={app}/MyProg.exe

    [Code]

    procedure WordButtonOnClick(Sender: TObject);

    var

    Word: Variant;

    begin

    MsgBox('WORD', mbInformation, mb_Ok);

    end;

    procedure CreateButton(ALeft, ATop: Integer; ACaption: String; ANotifyEvent: TNotifyEvent);

    begin

    with TButton.Create(WizardForm) do begin

    Left := ALeft;

    Top := ATop;

    Width := WizardForm.CancelButton.Width;

    Height := WizardForm.CancelButton.Height;

    Caption := ACaption;

    OnClick := ANotifyEvent;

    Parent := WizardForm.WelcomePage;

    end;

    end;





    procedure InitializeWizard();

    var

    Left, Top, TopInc: Integer;

    begin

    Left := WizardForm.WelcomeLabel2.Left;

    TopInc := WizardForm.CancelButton.Height + 8;

    Top := WizardForm.WelcomeLabel2.Top + WizardForm.WelcomeLabel2.Height - 4*TopInc;



    CreateButton(Left, Top, '&Word...', @WordButtonOnClick); ;要先定义后使用

    end;







    页面变量

    TInputFileWizardPage

    TInputQueryWizardPage

    TInputOptionWizardPage


    //下一步按钮的函数
    function NextButtonClick(CurPageID: Integer): Boolean;
    begin
    Result := true;
    end

    function BackButtonClick(CurPageID: Integer): Boolean;
    begin
    Result := true;


    end;

    文件操作:
    function RenameFile(const OldName, NewName: string): Boolean;
    function DeleteFile(const FileName: string): Boolean;
    function DelTree(const Path: String; const IsDir, DeleteFiles, DeleteSubdirsAlso: Boolean): Boolean

    创建页面
    function CreateInputDirPage(const AfterID: Integer; const ACaption, ADescription, ASubCaption: String; AAppendDir: Boolean; ANewFolderName: String): TInputDirWizardPage;

    function CreateInputFilePage(const AfterID: Integer; const ACaption, ADescription, ASubCaption: String): TInputFileWizardPage;

    function CreateInputOptionPage(const AfterID: Integer; const ACaption, ADescription, ASubCaption: String; Exclusive, ListBox: Boolean): TInputOptionWizardPage;

    function CreateInputQueryPage(const AfterID: Integer; const ACaption, ADescription, ASubCaption: String): TInputQueryWizardPage;

    function CreateOutputMsgMemoPage(const AfterID: Integer; const ACaption, ADescription, ASubCaption, AMsg: String): TOutputMsgMemoWizardPage;

    function CreateOutputMsgPage(const AfterID: Integer; const ACaption, ADescription, AMsg: String): TOutputMsgWizardPage;

    inno setup 技巧
    [code]
    procedure InitializeWizard();
    begin
    WizardForm.LICENSEACCEPTEDRADIO.Checked := true;
    end;
    2、自定义安装程序右上角图片大小
    [code]
    procedure InitializeWizard();
    begin
    WizardForm.WizardSmallBitmapImage.=150; //设置页眉图片的大小
    WizardForm.WizardSmallBitmapImage.left:=WizardForm.width-150; //设置左边页眉留出的空隙
    WizardForm.PAGENAMELABEL.=0; //设置标题文字显示的大小
    WizardForm.PAGEDESCRIPTIONLABEL.=0; //设置标题文字显示的大小
    end;
    或者
    //自定义安装向导小图片
    [code]
    procedure InitializeWizard();
    begin
    Wizardform.WizardSmallBitmapImage.left:= WizardForm.width-164; //自定义安装向导小图片显示位置
    WizardForm.WizardSmallBitmapImage.=164; //自定义安装向导小图片宽度
    Wizardform.PageNameLabel.= 495 - 164 -36; //这儿必须定义,数值根据图片宽度更改,显示软件名称的位置
    Wizardform.PageDescriptionLabel.= 495 - 164 -42; //显示页面信息的位置
    end;
    3、自定义BeveledLabel显示代码
    [code]
    procedure InitializeWizard();
    begin
    WizardForm.BeveledLabel.Enabled:=true; //允许显示
    WizardForm.BeveledLabel.Font.Color:=$00058451;; //显示颜色
    WizardForm.BeveledLabel.Font.Style := WizardForm.BeveledLabel.Font.Style + [fsBold]; //显示字体
    WizardForm.BeveledLabel.Left:=5; //显示位置
    end;
    4、自定义安装向导图片
    [code]
    procedure InitializeWizard();
    begin
    Wizardform.WELCOMELABEL1.left:= 18; //自定义欢迎页面标题1显示位置
    Wizardform.WELCOMELABEL2.left:= 18; //自定义欢迎页面标题2显示位置
    Wizardform.WizardBitmapImage.left:= WizardForm.width-164 //自定义安装向导图片显示位置(显示大小,此处为居右显示)
    end;
    5、显示出组件选择框
    [Types]
    Name: full; Description: 推荐
    Name: default; Description: 典型
    Name: custom; Description: 自定义; Flags: iscustom
    ;告诉安装程序这个类型是自定义类型。必须定义iscustom这个参数,才能显示出组件选择框
    6、定义[Messages]的颜色
    [code]
    procedure InitializeWizard();
    begin
    WizardForm.BeveledLabel.Enabled:= True;
    WizardForm.BeveledLabel.Font.Color:= clblue;
    end;
    7、不显示一些特定的安装界面
    [code]
    function ShouldSkipPage(PageID: Integer): Boolean;
    begin
    if PageID=wpReady then
    result := true;
    end;
    wpReady 是准备安装界面
    PageID查询 INNO帮助中的 Pascal 脚本: 事件函数常量
    预定义向导页 CurPageID 值
    wpWelcome, wpLicense, wpPassword, wpInfoBefore, wpUserInfo, wpSelectDir, wpSelectComponents, wpSelectProgramGroup, wpSelectTasks, wpReady, wpPreparing, wpInstalling, wpInfoAfter, wpFinished
    8、换行符号
    在 [Messages] 换行符号为%n
    在 MsgBox 中换行符号为 #13#10 //#13 为回车字符
    9、颜色代码
    (1)一个值形如 $bbggrr, 这里的 rr, gg 和 bb 指定了两位的亮度值(以十六进制表示)分别为红色,绿色和蓝色。
    (2)预定义的颜色名称:
    clBlack(黑色),clMaroon(暗红),clGreen(绿色),clOlive(橄榄绿),
    clNavy(深蓝),clPurple(紫色),clTeal(深青),clGray(灰色),
    clSilver(浅灰),clRed(红色),clLime(浅绿),clYellow(黄色),
    clBlue(蓝色),clFuchsia(紫红),clAqua(青绿),clWhite(白色)。
    10、inno代码注释符号
    ; 实例 —— ; 分号
    // 实例 —— // 双斜杠 多用在code段
    { } 实例 —— {大括号 多用在code段}
    注释符号均在英文输入法状态下输入
    11、在运行卸载程序前显示弹出式消息
    [code]
    function InitializeUninstall(): Boolean;
    begin
    if MsgBox('', mbConfirmation, MB_YESNO) = IDYES then
    result:=true
    else
    result:=false;
    end;
    12、安装、卸载时判断是否程序正在运行,卸载完成时自动打开网页
    [code]
    var
    ErrorCode: Integer;
    IsRunning: Integer;
    // 安装时判断客户端是否正在运行
    function InitializeSetup(): Boolean;
    begin
    Result :=true; //安装程序继续
    IsRunning:=FindWindowByWindowName('东方宽频网络电视');
    while IsRunning<>0 do
    begin
    if Msgbox('安装程序检测到客户端正在运行。' #13#13 '您必须先关闭它然后单击“是”继续安装,或按“否”退出!', mbConfirmation, MB_YESNO) = idNO then
    begin
    Result :=false; //安装程序退出
    IsRunning :=0;
    end else begin
    Result :=true; //安装程序继续
    IsRunning:=FindWindowByWindowName('东方宽频网络电视');
    end;
    end;
    end;
    // 卸载时判断客户端是否正在运行
    function InitializeUninstall(): Boolean;
    begin
    Result :=true; //安装程序继续
    IsRunning:=FindWindowByWindowName('东方宽频网络电视');
    while IsRunning<>0 do
    begin

    if Msgbox('安装程序检测到客户端正在运行。' #13#13 '您必须先关闭它然后单击“是”继续安装,或按“否”退出!', mbConfirmation, MB_YESNO) = idNO then
    begin
    Result :=false; //安装程序退出
    IsRunning :=0;
    end else begin
    Result :=true; //安装程序继续
    IsRunning:=FindWindowByWindowName('东方宽频网络电视');
    end;
    end;
    end;
    procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
    begin
    case CurUninstallStep of
    usUninstall:
    begin // 开始卸载
    end;
    usPostUninstall:
    begin // 卸载完成
    // MsgBox('CurUninstallStepChanged:' #13#13 'Uninstall just finished.', mbInformation, MB_OK);
    // ...insert code to perform post-uninstall tasks here...
    ShellExec('open', 'http://www.dreams8.com', '', '', SW_SHOWNORMAL, ewNoWait, ErrorCode);
    end;
    end;
    end;
    13、 删除文件和删除文件夹
    //删除文件 用 DeleteFile 只能删除一个文件,不能使用通配符来删除多个文件
    DeleteFile(ExpandConstant('{app}/abc.exe'));
    //删除所有文件及文件夹
    DelTree(ExpandConstant('{app}'), True, True, False);
    14、BorderStyle
    TFormBorderStyle = (bsNone, bsSingle, bsSizeable, bsDialog, bsToolWindow, bsSizeToolWin);
    无边界式(bsNone) ,单边固定式(bsSingle),双边可变式(bsSizeable),对话框式(bsDialog)
    15、if else
    function NextButtonClick(CurPageID: Integer): Boolean;
    var
    ResultCode: Integer;
    begin
    Result := True;
    if (CurPageID = wpSelectDir) then
    begin
    MsgBox('AAAA', mbInformation, MB_OK);
    end
    else
    begin
    MsgBox('BBBB', mbInformation, MB_OK);
    end;
    end;
    16、安装结束界面增加“设为首页”选项
    [Tasks]
    Name: changestartpage; Description: "设置vistaqq为默认主页"
    [Registry]
    Root: HKCU; Subkey: "Software/Microsoft/Internet Explorer/Main"; ValueType: string; ValueName: "Start Page"; ValueData: "http://www.vistaqq.com"; tasks: changestartpage
    17、添加“关于”和网站链接按钮
    [Code]
    procedure URLLabelOnClick(Sender: TObject);
    var
    ErrorCode: Integer;
    begin
    ShellExec('open', 'http://www.vistaqq.com', '', '', SW_SHOWNORMAL, ewNoWait, ErrorCode);
    end;
    procedure AboutButtonOnClick(Sender: TObject);
    begin
    MsgBox(#13 'Vista 状态条风格盘符' #13 #13'本软件由jinn制作,希望各位登陆中天VIP工作室!' #13#13 '版权所有 (C) 中天VIP工作室', mbInformation, MB_OK);
    end;
    var
    AboutButton, CancelButton: TButton;
    URLLabel: TNewStaticText;
    procedure InitializeWizard();
    begin
    { Create the pages }
    WizardForm.PAGENAMELABEL.Font.Color:= clred;
    WizardForm.PAGEDESCRIPTIONLABEL.Font.Color:= clBlue;
    WizardForm.WELCOMELABEL1.Font.Color:= clGreen;
    WizardForm.WELCOMELABEL2.Font.Color:= clblack;
    CancelButton := WizardForm.CancelButton;
    AboutButton := TButton.Create(WizardForm);
    AboutButton.Left := WizardForm.ClientWidth - CancelButton.Left - CancelButton.Width;
    AboutButton.Top := CancelButton.Top;
    AboutButton.Width := CancelButton.Width;
    AboutButton.Height := CancelButton.Height;
    AboutButton.Caption := '&About';
    AboutButton.OnClick := @AboutButtonOnClick;
    AboutButton.Parent := WizardForm;
    URLLabel := TNewStaticText.Create(WizardForm);
    URLLabel.Caption := '中天VIP工作室';
    URLLabel.Cursor := crHand;
    URLLabel.OnClick := @URLLabelOnClick;
    URLLabel.Parent := WizardForm;
    { Alter Font *after* setting Parent so the correct defaults are inherited first }
    URLLabel.Font.Style := URLLabel.Font.Style + [fsUnderline];
    URLLabel.Font.Color := clBlue;
    URLLabel.Top := AboutButton.Top + AboutButton.Height - URLLabel.Height - 2;
    URLLabel.Left := AboutButton.Left + AboutButton.Width + ScaleX(20);
    end;
    18、去掉安装程序左上角“关于安装程序”的代码
    procedure InitializeWizard();
    begin
    WizardForm.BorderIcons:= [biMinimize];
    end;
    procedure CurPageChanged(CurPage: Integer);
    begin
    if CurPage=wpWelcome then
    WizardForm.BorderIcons:= [biSystemMenu, biMinimize];
    end;
    或者
    procedure InitializeWizard();
    begin
    WizardForm.BORDERICONS := [biHelp, biSystemMenu, biMinimize];
    end;
    19、自定义BeveledLabel文字
    [Messages]
    BeveledLabel=中天VIP工作室
    20、自定义安装程序界面左上角“安装”文字
    [message]
    SetupAppTitle=需要的字
    SetupWindowTitle=需要的字
    21、自定义安装程序版本号
    VersionInfoVersion=1.1
    VersionInfoTextVersion=1.1
    -----------------------------------------------------------------------
     
     
    [_ISTool]
    EnableISX=true
    
    [Setup]
    AppName=YourAppName
    AppVerName=Your App Version 1.0.0
    MinVersion=4.1,4.0
    DefaultDirName={pf}\Your Default Directory
    DefaultGroupName=Your Default Group Name
    Compression=lzma
    SolidCompression=true
    OutputBaseFilename=Your Output File Name
    DisableDirPage=true
    DisableProgramGroupPage=true
    DisableReadyPage=false
    DisableReadyMemo=true
    
    [Files]
    Source: C:\Program Files\ISTool\isxdl.dll; Flags: dontcopy
    
    [Messages]
    WinVersionTooLowError=YourAppName requires Windows 2000, Windows XP or later.
    
    [Icons]
    Name: {group}\Uninstall YourAppName; Filename: {uninstallexe}
    
    [Code]
    var
    dotnetRedistPath: string;
    downloadNeeded: boolean;
    dotNetNeeded: boolean;
    memoDependenciesNeeded: string;
    uninstaller: String;
    ErrorCode: Integer;
    
    procedure isxdl_AddFile(URL, Filename: PChar);
    external 'isxdl_AddFile@files:isxdl.dll stdcall';
    function isxdl_DownloadFiles(hWnd: Integer): Integer;
    external 'isxdl_DownloadFiles@files:isxdl.dll stdcall';
    function isxdl_SetOption(Option, Value: PChar): Integer;
    external 'isxdl_SetOption@files:isxdl.dll stdcall';
    
    const
    dotnetRedistURL = 'http://download.microsoft.com/download/5/6/7/567758a3-759e-473e-bf8f-52154438565a/dotnetfx.exe';
    const
    exeURL = 'http://www.pathtoyoursite.com/setup.exe';
    const
    msiURL = 'http://www.pathtoyoursite.com/Installation.msi';
    
    function InitializeSetup(): Boolean;
    
    begin
    Result := true;
    dotNetNeeded := false;
    
    if not FileExists(ExpandConstant('{tmp}\setup.exe')) or not FileExists(ExpandConstant('{tmp}\Installation.msi'))  then
    begin
    isxdl_AddFile(exeURL, ExpandConstant('{tmp}\setup.exe'));
    isxdl_AddFile(msiURL, ExpandConstant('{tmp}\Installation.msi'));
    downloadNeeded := true;
    end
    
    // See if the .NET Framework is already installed
    if (not RegKeyExists(HKLM, 'Software\Microsoft\.NETFramework\policy\v2.0')) then begin
    dotNetNeeded := true;
    if (not IsAdminLoggedOn()) then begin
    MsgBox('YourAppName needs the Microsoft .NET Framework to be installed by an Administrator', mbInformation, MB_OK);
    Result := false;
    end else begin
    memoDependenciesNeeded := memoDependenciesNeeded + '      .NET Framework' ;
    dotnetRedistPath := ExpandConstant('{src}\dotnetfx.exe');
    if not FileExists(dotnetRedistPath) then begin
    dotnetRedistPath := ExpandConstant('{tmp}\dotnetfx.exe');
    if not FileExists(dotnetRedistPath) then begin
    isxdl_AddFile(dotnetRedistURL, dotnetRedistPath);
    downloadNeeded := true;
    end;
    end;
    SetIniString('install', 'dotnetRedist', dotnetRedistPath, ExpandConstant('{tmp}\dep.ini'));
    end;
    end;
    
    end;
    
    function NextButtonClick(CurPage: Integer): Boolean;
    var
    hWnd: Integer;
    ResultCode: Integer;
    
    begin
    Result := true;
    
    if CurPage = wpReady then begin
    
    hWnd := StrToInt(ExpandConstant('{wizardhwnd}'));
    
    // don't try to init isxdl if it's not needed because it will error on < ie 3
    if downloadNeeded then begin
    
    isxdl_SetOption('label', 'Downloading YourAppName Components');
    isxdl_SetOption('description', 'YourAppName needs to install some components. Please wait while Setup is downloading extra files to your computer.');
    if isxdl_DownloadFiles(hWnd) = 0 then Result := false;
    end;
    if (Result = true) and (dotNetNeeded = true) then begin
    if Exec(ExpandConstant(dotnetRedistPath), '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then begin
    // handle success if necessary; ResultCode contains the exit code
    if not (ResultCode = 0) then begin
    Result := false;
    end;
    end else begin
    // handle failure if necessary; ResultCode contains the error code
    Result := false;
    end;
    end;
    FileCopy(ExpandConstant('{tmp}\Installation.msi'),  ExpandConstant('{app}\Installation.msi'), false);
    FileCopy(ExpandConstant('{tmp}\setup.exe'),  ExpandConstant('{app}\setup.exe'), false);
    end;
    end;
    
    function UpdateReadyMemo(Space, NewLine, MemoUserInfoInfo, MemoDirInfo, MemoTypeInfo, MemoComponentsInfo, MemoGroupInfo, MemoTasksInfo: String): String;
    var
    s: string;
    
    begin
    if memoDependenciesNeeded <> '' then s := s + 'Dependencies to install:' + NewLine + memoDependenciesNeeded + NewLine;
    s := s + MemoDirInfo + NewLine + NewLine;
    
    Result := s
    end;
    
    [Run]
    Filename: msiexec.exe; Parameters: "/i ""{tmp}\Installation.msi "" /qb"
    
    [UninstallRun]
    Filename: msiexec.exe; Parameters: "/x ""{app}\Installation.msi "" /quiet"
     
     
    --------------------------------------------------
     
    Files]
    
    Source: MyPackage.msi; DestDir: {tmp}
    [Run]
    Filename: {%COMSPEC}; Parameters: /C msiexec -i {tmp}\MyPacakge.msi; WorkingDir:{tmp}; StatusMsg: “Installing my package”
    --------------------------------------------
    // 或者
    [Run]
    Filename: msiexec.exe; Parameters: “-i “”{src}\MyPacakge.msi”" -qn”; WorkingDir: “{src}”; StatusMsg: “Installing my package”
  • 相关阅读:
    黑客无处不在
    微博对我的影响
    WPF Chart DynamicDataDisplay的横坐标显示日期的解决方案
    java虚拟机中的字节码
    python解释器的使用
    Python学习环境设置
    变量的概念
    创建虚拟环境和常用包
    第三章笔记
    第一章笔记
  • 原文地址:https://www.cnblogs.com/fx2008/p/2375082.html
Copyright © 2011-2022 走看看