zoukankan      html  css  js  c++  java
  • InnoSetup使用教程(收藏)

    1.检测.Net Framework运行环境
      安装程序自动检测安装.Net Framework运行环境(使用InnoSetup) 
    最近公司开发了一个WinForm的项目,部署人员在制作安装程序的时候问到怎么在安装程序中自动检测是否安装.Net Framework,由于是使用InnoSetup制作的安装程序,InnoSetup本身是支持Pascal脚本的,于是撰写了如下的代码来实现自动检测安装.Net Framework的功能。
     
    InnoSetup可在在脚本中插入[Code]代码段,其中的代码可以通过事件驱动,支持的主要事件如下:    
     
    •function InitializeSetup(): Boolean; ——安装程序初始化,返回值决定安装程序是否继续执行。    
    •function NextButtonClick(CurPageID: Integer): Boolean; ——点击下一步按钮,返回值决定安装程序是否继续执行。    
    •function BackButtonClick(CurPageID: Integer): Boolean; ——点击上一步按钮,返回值决定安装程序是否继续执行。    
    •function InitializeUninstall(): Boolean; ——卸载程序初始化,返回值决定卸载程序是否继续执行。  
    •... 
    从这些事件我们可以看到InitializeSetup()满足我们的要求,我们可以在这个时候去检查注册表或者是系统文件来判断客户机器上是否安装了.Net Framework,从而进行自动安装或者下载安装的操作。
     
    最终代码如下: 
    --------------------------------------------------------------------------------
    [Code]
     
    function InitializeSetup: Boolean;
    var Path:string ;
        ResultCode: Integer;
        dotNetV2RegPath:string;
        dotNetV2DownUrl:string;
        dotNetV2PackFile:string;
    begin
     
      dotNetV2RegPath:='SOFTWARE\Microsoft\.NETFramework\policy\v2.0';
      dotNetV2DownUrl:='http://www.xxx.com/down/dotNetFx_v2.0(x86).exe';
      dotNetV2PackFile:='{src}\dotNetFx_v2.0(x86).exe';
      if RegKeyExists(HKLM, dotNetV2RegPath) then
      begin
        Result := true;
      end
      else
      begin
        if MsgBox('系统检测到您没有安装.Net Framework2.0运行环境,是否立即安装?', mbConfirmation, MB_YESNO) = idYes then
        begin
          Path := ExpandConstant(dotNetV2PackFile);
          if(FileOrDirExists(Path)) then
          begin
            Exec(Path, '/q', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode);
            if RegKeyExists(HKLM, dotNetV2RegPath) then
            begin
               Result := true;
            end
            else
            begin
               MsgBox('未能成功安装.Net Framework2.0运行环境,系统将无法运行,本安装程序即将退出!',mbInformation,MB_OK);
            end
          end
          else
          begin
            if MsgBox('软件安装目录中没有包含.Net Framework的安装程序,是否立即下载后安装?', mbConfirmation, MB_YESNO) = idYes then
            begin
              Path := ExpandConstant('{pf}\Internet Explorer\iexplore.exe');
              Exec(Path, dotNetV2DownUrl , '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode);
              MsgBox('请安装好.Net Framework2.0环境后,再运行本安装包程序!',mbInformation,MB_OK);
              Result := false;
            end
            else
            begin
              MsgBox('不下载安装.Net Framework2.0运行环境,系统将无法运行,本安装程序即将退出!',mbInformation,MB_OK);
              Result := false;
            end
          end
        end
        else
        begin
          MsgBox('没有安装.Net Framework2.0运行环境,系统将无法运行,本安装程序即将退出!',mbInformation,MB_OK);
          Result := false;
        end;
      end;
    end;
     
    使用的时候将上面的代码段复制到您的安装脚本中进行编译(您可以更改dotNetV2RegPath、dotNetV2PackFile和dotNetV2DownUrl来更改默认的参数),最后将.Net Framework的安装包“dotNetFx_v2.0(x86).exe”放在与安装程序同一目录中即可。
     
    安装程序执行时将检查客户计算机是否安装了.Net Framework 2.0,如果没有安装,则会调用同一目录下的.Net安装包进行安装,如同一目录下没有.Net安装包,则提示从网络上下载.Net安装包。.Net安装包安装完毕后将自动继续执行您的安装程序。

    2.关于Inno Setup如何修改安装向导内的图片
    这个很简单,只需来到Inno Setup程序的根目录找到
    WizModernSmallImage.BMP 与 WizModernImage.bmp 这个2个图片文件替换即可。
    其中:WizModernImage.bmp为左侧图 
    如图(1); WizModernSmallImage.BMP则为右上角图标 
    如图(2)。
    说明:WizModernImage.bmp这个图片的大小为:164×314 WizModernSmallImage.BMP这个图片的大小为:55×55 (这2个图片大小 我是按照以前默认大小改的,其它比例大小我没试过,有兴趣的话可以自己试下。)


    三:关于Inno Setup如何在安装分割线里加入文字
    只需要加入一个[Messages]段并在此段下输入以下代码:
    BeveledLabel=Professional
    代码说明:其中绿色部分Professional为自定义文字,可以自行随意输入!

    四、关于Inno Setup在安装欢迎界面时添加自己的文字方法
    方法(1):
    1.添加[Code]段
    2.在此段下输入以下代码:
    procedure InitializeWizard();
    var
    LabelDate: Tlabel;
    begin
    WizardForm.WelcomeLabel2.Autosize := true;
    LabelDate := Tlabel.Create(WizardForm);
    LabelDate.Autosize := true;
    LabelDate.Caption := '本程序由Professional制作'#10#13#10#13'欢迎PC爱好者共同讨论'#10#13#10#13'Professional: http://hi.baidu.com/pfia';
    LabelDate.Parent := WizardForm.WelcomePage;
    LabelDate.Left := WizardForm.WelcomeLabel2.Left;
    LabelDate.Top := WizardForm.WelcomeLabel2.Top +WizardForm.WelcomeLabel2.Height +80;
    end;
    方法(2):
    1.添加[Messages]段;
    2.在此段下输入该代码:
    ClickNext=单击“下一步”继续,或单击“取消”退出安装程序。%n%n%n%n%n%n%n%n本程序由Professional制作%n%n欢迎PC爱好者共同讨论%n%nProfessional: http://hi.baidu.com/pfia
    说明:
    1.方法一与方法二中代码绿色字部分为个人喜好可随意更改处。
    2.方法一绿色字中#10#13为组合换行符;方法二绿色字中%n为换行符。<学过C的朋友应该知道在C语言中
       换行符为\n,千万不要搞混。。>换行符可按照自己喜好随意增减。
    3.千万不要忘掉方法一代码绿色字内的一对单引号''。(因为那些文字都是字符串,方法2中不用添加。)

    五、关于Inno Setup显示关于按钮以及网站超链接
    添加[Code]段,在此段下输入代码:
    procedure AboutButtonOnClick(Sender: TObject);
    begin
    MsgBox('欢迎访问Professional'#13#13'http://hi.baidu.com/pfia', mbInformation, mb_Ok);
    end;
    procedure URLLabelOnClick(Sender: TObject);
    var
    ErrorCode: Integer;
    begin
    ShellExec('open', 'http://hi.baidu.com/pfia', '', '', SW_SHOW, ewNoWait, ErrorCode)
    end;
    procedure InitializeWizard();
    var
    AboutButton: TButton;
    URLLabel: TNewStaticText;
    begin
    AboutButton := TButton.Create(WizardForm);
    AboutButton.Left := WizardForm.ClientWidth - WizardForm.CancelButton.Left - WizardForm.CancelButton.Width;
    AboutButton.Top := WizardForm.CancelButton.Top;
    AboutButton.Width := WizardForm.CancelButton.Width;
    AboutButton.Height := WizardForm.CancelButton.Height;
    AboutButton.Caption := '关于(&A)';
    AboutButton.OnClick := @AboutButtonOnClick;
    AboutButton.Parent := WizardForm;
    URLLabel := TNewStaticText.Create(WizardForm);
    URLLabel.Top := AboutButton.Top + AboutButton.Height - URLLabel.Height - 2;
    URLLabel.Left := AboutButton.Left + AboutButton.Width + 10;
    URLLabel.Caption := 'Professional';
    URLLabel.Font.Style := [fsBold, fsUnderline];
    URLLabel.Font.Color := clBlue;
    URLLabel.Cursor := crHand;
    URLLabel.OnClick := @URLLabelOnClick;
    URLLabel.Font.Name := '宋体';
    URLLabel.Font.Height := ScaleY(-13);
    URLLabel.Parent := WizardForm;
    URLLabel.Hint := '点击访问相关网站';
    URLLabel.ShowHint := True;
    end;
    代码说明:
    ①:绿色代码部分是点击关于按钮后弹出的信息,#13为换行符。
    ②:紫色代码部分是点击超链接信息后转到的网站地址。
    ③:粉色代码部分为关于按钮的名称,(&A)为快捷键,可随意填写字母。
    ④:蓝色代码部分为超链接文字名称。
    ⑤:黄色代码部分为超链接文字名称颜色,clBlue 可改为其它颜色。如:
    clBlack(黑色),clMaroon(暗红),clGreen(绿色),clOlive(橄榄绿),
    clNavy(深蓝),clPurple(紫色),clTeal(深青),clGray(灰色),
    clSilver(浅灰),clRed(红色),clLime(浅绿),clYellow(黄色),
    clBlue (蓝色),clFuchsia(紫红),clAqua(青绿),clWhite(白色)。
    ⑥:红色代码部分为超链接文字名称字体,可修改为黑体字型等。
    ⑦:橙色代码部分为鼠标指针放到超链接文字标题上显示的提示语。

    六、
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
  • 相关阅读:
    吴裕雄 Bootstrap 前端框架开发——Bootstrap 图片:响应式图片
    吴裕雄 Bootstrap 前端框架开发——Bootstrap 图片:图片响应式 (将很好地扩展到父元素)
    吴裕雄 Bootstrap 前端框架开发——Bootstrap 图片:缩略图功能
    吴裕雄 Bootstrap 前端框架开发——Bootstrap 图片:将图片变为圆形 (IE8 不支持)
    吴裕雄 Bootstrap 前端框架开发——Bootstrap 图片:为图片添加圆角 (IE8 不支持)
    吴裕雄 Bootstrap 前端框架开发——Bootstrap 图片
    吴裕雄 Bootstrap 前端框架开发——Bootstrap 按钮:分割按钮
    吴裕雄 Bootstrap 前端框架开发——Bootstrap 按钮:内嵌下拉菜单的按钮组
    吴裕雄 Bootstrap 前端框架开发——Bootstrap 按钮:自适应大小的按钮组
    吴裕雄 Bootstrap 前端框架开发——Bootstrap 按钮:按钮组
  • 原文地址:https://www.cnblogs.com/lonsn/p/2717414.html
Copyright © 2011-2022 走看看