Inno Setup[1]  用Delphi写成,其官方网站同时也提供源程序免费下载。它虽不能与Installshield这类恐龙级的安装制作软件相比,但也当之无愧算是后起之秀。Inno Setup是一个免费的安装制作软件,小巧、简便、精美是其最大特点,支持pascal脚本,能快速制作出标准Windows2000风格的安装界面,足以完成一般安装任务。

用innoSetup做应用程序安装包的示例脚本(.iss文件),具体要看innoSetup附带的文档,好象是pascal语言写的脚本。

示例1(应用程序.exe,客户端安装):

;{089D6802-6CD3-4E45-B8D5-AC9ED99CE371}; 脚本由 Inno Setup 脚本向导 生成!
; 有关创建 Inno Setup 脚本文件的详细资料请查阅帮助文档!

[Setup]
; 注: AppId的值为单独标识该应用程序。
; 不要为其他安装程序使用相同的AppId值。
; (生成新的GUID,点击 工具|在IDE中生成GUID。)
AppId={{5E012E21-42EE-4840-A000-35F9FAB886E9}
AppName=AIS_Client
AppVerName=AIS_Client
AppPublisher=公司名

DefaultDirName={pf}\AIS_Client
DefaultGroupName=AIS_Client
OutputBaseFilename=AIS_Client
Compression=lzma
SolidCompression=yes
SetupIconFile=D:\AIS\AIS 打包程序\AISGUI.ico
LicenseFile=C:\Documents and Settings\Administrator\桌面\许可协议.txt

[Languages]
Name: "chinesesimp"; MessagesFile: "compiler:Default.isl"

[Files]
Source: "D:\AIS\AIS 打包程序\AIS_client_exe\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; 注意: 不要在任何共享系统文件上使用“Flags: ignoreversion”

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"

[Icons]
Name: "{group}\AIS客户端"; Filename: "{app}\AISGUI.exe"
Name: "{group}\AIS客户端参数配置工具"; Filename: "{app}\ClientConfig.exe"
Name: "{group}\AIS服务设置工具"; Filename: "{app}\ServiceIPManage.exe"
Name: "{group}\AIS数据库参数配置工具"; Filename: "{app}\DataBaseConfig.exe"
;Name: "{group}\门控服务端"; Filename: "{app}\Access_server\SecurityWare.exe"
;在开始菜单->所有程序->伴网书童里添加一个删除快捷键。
Name: "{group}\卸载"; Filename: {uninstallexe}
Name: "{commondesktop}\AIS客户端"; Filename: "{app}\AISGUI.exe"; Tasks: desktopicon
;Name: "{commondesktop}\门控服务端"; Filename: "{app}\Access_server\SecurityWare.exe"; Tasks: desktopicon

[Run]
;Filename: "{app}\Access_server\SecurityWare.exe"; Description: "{cm:LaunchProgram,AIS}"; Flags: nowait postinstall skipifsilent shellexec
Filename: "{app}\AISGUI.exe"; Description: "{cm:LaunchProgram,AIS}"; Flags: nowait postinstall skipifsilent shellexec

[Registry]
;添加开机启动
Root: HKLM; Subkey: "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"; ValueType: string; ValueName:"ais"; ValueData:"{app}\AISGUI.exe";  Flags:uninsdeletevalue

[Code]
{卸载时判断主程序是否在运行}
var
is_Sys , is_value: integer;
S_syschar, S_currentchar, S_current,S_sys, S,ResultStr : string;
I ,CloseNum: Integer;
ErrorCode: Integer;
Guid_names,window_name : TArrayOfString;
bool  : Boolean;
const AppName='{5E012E21-42EE-4840-A000-35F9FAB886E9}_is1';

{程序安装前判断主程序是否在运行}
function InitializeSetup(): Boolean;
var
  ResultCode: Integer;
begin
  if RegGetSubkeyNames(HKEY_LOCAL_MACHINE,'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall',Guid_names) then
  begin
    for I:=0 to GetArrayLength(Guid_names)-1 do
    begin
      S := Guid_names[i];
      //注册表中找到了此键
      if AppName=Guid_names[i] then
      begin
        bool := RegQueryStringValue(HKEY_LOCAL_MACHINE,'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\'+S,'UninstallString',ResultStr);
        //ResultStr := RemoveQuotes(ResultStr);
        if bool then
        begin
          if MsgBox('安装程序检测到当前计算机已经安装了AIS客户端。' #13#13 '您是否要卸载AIS客户端?',  mbConfirmation, MB_YESNO) = IDYES then
            //   ShellExec('', ExpandConstant('{app}\unins000.exe'), '','', SW_SHOW, ewNoWait, ResultCode);
            begin
              Exec(RemoveQuotes(ResultStr), '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode);
              Result := false;
            end
        end
        break;
      end
      else
      //zdx 5.8 判断是否已经打开了一个安装程序
      begin
        if FindWindowbyWindowName('安装 - AIS_Client')<>0 then
        begin
          MsgBox('安装程序检测到有另外一个安装程序已经在运行了', mbConfirmation, MB_OK);
          Result := false;
          break;
        end
      end
    end;
    if I= GetArrayLength(Guid_names) then
      Result := true;
  end
  else
    Result := true;
end;

//当用户单击cancel的时候,删除掉拷贝到系统的文件夹
procedure CancelButtonClick(CurPageID: Integer; var Cancel, Confirm: Boolean);
begin
end ;

//卸载密码验证函数
function AskPassword(): Boolean;
var
   Form: TSetupForm;
   OKButton, CancelButton: TButton;
   PwdEdit: TPasswordEdit;
begin
   Result := false;
   Form := CreateCustomForm();
   try
Form.ClientWidth := ScaleX(256);
Form.ClientHeight := ScaleY(100);
Form.Caption := '密码验证';
Form.BorderIcons := [biSystemMenu];
Form.BorderStyle := bsDialog;
Form.Center;

OKButton := TButton.Create(Form);
OKButton.Parent := Form;
OKButton.Width := ScaleX(75);
OKButton.Height := ScaleY(23);
OKButton.Left := Form.ClientWidth - ScaleX(75 + 6 + 75 + 50);
OKButton.Top := Form.ClientHeight - ScaleY(23 + 10);
OKButton.Caption := '确定';
OKButton.ModalResult := mrOk;
OKButton.Default := true;

CancelButton := TButton.Create(Form);
CancelButton.Parent := Form;
CancelButton.Width := ScaleX(75);
CancelButton.Height := ScaleY(23);
CancelButton.Left := Form.ClientWidth - ScaleX(75 + 50);
CancelButton.Top := Form.ClientHeight - ScaleY(23 + 10);
CancelButton.Caption := '取消';
CancelButton.ModalResult := mrCancel;
CancelButton.Cancel := True;

PwdEdit := TPasswordEdit.Create(Form);
PwdEdit.Parent := Form;
PwdEdit.Width := ScaleX(210);
PwdEdit.Height := ScaleY(23);
PwdEdit.Left := ScaleX(23);
PwdEdit.Top := ScaleY(23);

Form.ActiveControl := PwdEdit;

if Form.ShowModal() = mrOk then
begin
   Result := PwdEdit.Text = 'bw12345678';
   if not Result then
         MsgBox('密码错误', mbInformation, MB_OK);
end;
   finally
Form.Free();
   end;
end;

//卸载程序的时候判断是否在运行
function InitializeUninstall(): Boolean;
begin
  begin
  //密码验证
  //Result :=  AskPassword();
  Result := TRUE;
//  DelTree(ExpandConstant('{app}\*'), False, True, True);
  end
end;

//提示卸载完后重启计算机
function UninstallNeedRestart(): Boolean;
begin
   Result := False;
   DelTree(ExpandConstant('{app}\*'), False, True, True);
   DelTree(ExpandConstant('{app}'), True, True, True);
end;

示例2(windows service,服务端安装):

;{089D6802-6CD3-4E45-B8D5-AC9ED99CE371}; 脚本由 Inno Setup 脚本向导 生成!
; 有关创建 Inno Setup 脚本文件的详细资料请查阅帮助文档!

[Setup]
; 注: AppId的值为单独标识该应用程序。
; 不要为其他安装程序使用相同的AppId值。
; (生成新的GUID,点击 工具|在IDE中生成GUID。)
AppId={{D0D0B722-C6F9-4A89-AB56-1417B9BD1400}
AppName=AIS_Server
AppVerName=AIS_Server
AppPublisher=公司名

DefaultDirName={pf}\AIS_Server
DefaultGroupName=AIS_Server
OutputBaseFilename=AIS_Server
Compression=lzma
SolidCompression=yes
SetupIconFile=D:\AIS\AIS 打包程序\AISGUI.ico
LicenseFile=C:\Documents and Settings\Administrator\桌面\许可协议.txt

[Languages]
Name: "chinesesimp"; MessagesFile: "compiler:Default.isl"

[Files]
Source: "D:\AIS\AIS 打包程序\AIS_server_exe\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; 注意: 不要在任何共享系统文件上使用“Flags: ignoreversion”

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"

[Icons]
Name: "{group}\AIS服务端参数配置工具"; Filename: "{app}\ServiceConfig.exe"
;Name: "{group}\AIS客户端"; Filename: "{app}\AIS_client_exe\AISGUI.exe"
;Name: "{group}\门控服务端"; Filename: "{app}\Access_server\SecurityWare.exe"
;在开始菜单->所有程序->伴网书童里添加一个删除快捷键。
Name: "{group}\卸载"; Filename: {uninstallexe}
;Name: "{commondesktop}\AIS客户端"; Filename: "{app}\AIS_client_exe\AISGUI.exe"; Tasks: desktopicon
;Name: "{commondesktop}\门控服务端"; Filename: "{app}\Access_server\SecurityWare.exe"; Tasks: desktopicon

[Run]
;Filename: "{app}\Access_server\SecurityWare.exe"; Description: "{cm:LaunchProgram,AIS}"; Flags: nowait postinstall skipifsilent shellexec
;Filename: "{app}\AIS_client_exe\AISGUI.exe"; Description: "{cm:LaunchProgram,AIS}"; Flags: nowait postinstall skipifsilent shellexec

[Registry]
;添加开机启动
;Root: HKLM; Subkey: "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"; ValueType: string; ValueName:"bwqc"; ValueData:"{app}\MSrv.exe";  Flags:uninsdeletevalue

[Code]
{卸载时判断主程序是否在运行}
var
is_Sys , is_value: integer;
S_syschar, S_currentchar, S_current,S_sys, S,ResultStr : string;
I ,CloseNum: Integer;
ErrorCode: Integer;
Guid_names,window_name : TArrayOfString;
bool  : Boolean;
const AppName='{D0D0B722-C6F9-4A89-AB56-1417B9BD1400}_is1';

{程序安装前判断主程序是否在运行}
function InitializeSetup(): Boolean;
var
  ResultCode: Integer;
begin
  if RegGetSubkeyNames(HKEY_LOCAL_MACHINE,'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall',Guid_names) then
  begin
    for I:=0 to GetArrayLength(Guid_names)-1 do
    begin
      S := Guid_names[i];
      //注册表中找到了此键
      if AppName = Guid_names[i] then
      begin
        bool := RegQueryStringValue(HKEY_LOCAL_MACHINE,'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\'+S,'UninstallString',ResultStr);
        //ResultStr := RemoveQuotes(ResultStr);
        if bool then
        begin
           if MsgBox('安装程序检测到当前计算机已经安装了AIS_Server。' #13#13 '您是否要卸载AIS_Server?',  mbConfirmation, MB_YESNO) = IDYES then
            //   ShellExec('', ExpandConstant('{app}\unins000.exe'), '','', SW_SHOW, ewNoWait, ResultCode);
            begin
              Exec(RemoveQuotes(ResultStr), '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode);
              Result := false;
            end
        end
        break;
      end
      else
      //zdx 5.8 判断是否已经打开了一个安装程序
      begin
        if FindWindowbyWindowName('安装 - AIS_Server')<>0 then
        begin
          MsgBox('安装程序检测到有另外一个安装程序已经在运行了', mbConfirmation, MB_OK);
          Result := false;
          break;
        end
      end
    end;
    if I = GetArrayLength(Guid_names) then
      Result := true;
  end
  else
    Result := true;
end;

//当用户单击cancel的时候,删除掉拷贝到系统的文件夹
procedure CancelButtonClick(CurPageID: Integer; var Cancel, Confirm: Boolean);
begin
end ;

//卸载密码验证函数
function AskPassword(): Boolean;
var
   Form: TSetupForm;
   OKButton, CancelButton: TButton;
   PwdEdit: TPasswordEdit;
begin
   Result := false;
   Form := CreateCustomForm();
   try
Form.ClientWidth := ScaleX(256);
Form.ClientHeight := ScaleY(100);
Form.Caption := '密码验证';
Form.BorderIcons := [biSystemMenu];
Form.BorderStyle := bsDialog;
Form.Center;

OKButton := TButton.Create(Form);
OKButton.Parent := Form;
OKButton.Width := ScaleX(75);
OKButton.Height := ScaleY(23);
OKButton.Left := Form.ClientWidth - ScaleX(75 + 6 + 75 + 50);
OKButton.Top := Form.ClientHeight - ScaleY(23 + 10);
OKButton.Caption := '确定';
OKButton.ModalResult := mrOk;
OKButton.Default := true;

CancelButton := TButton.Create(Form);
CancelButton.Parent := Form;
CancelButton.Width := ScaleX(75);
CancelButton.Height := ScaleY(23);
CancelButton.Left := Form.ClientWidth - ScaleX(75 + 50);
CancelButton.Top := Form.ClientHeight - ScaleY(23 + 10);
CancelButton.Caption := '取消';
CancelButton.ModalResult := mrCancel;
CancelButton.Cancel := True;

PwdEdit := TPasswordEdit.Create(Form);
PwdEdit.Parent := Form;
PwdEdit.Width := ScaleX(210);
PwdEdit.Height := ScaleY(23);
PwdEdit.Left := ScaleX(23);
PwdEdit.Top := ScaleY(23);

Form.ActiveControl := PwdEdit;

if Form.ShowModal() = mrOk then
begin
   Result := PwdEdit.Text = 'bw12345678';
   if not Result then
         MsgBox('密码错误', mbInformation, MB_OK);
end;
   finally
Form.Free();
   end;
end;

procedure CurStepChanged(CurStep: TSetupStep);//添加环境变量
var
  ResultCode: Integer;
begin
if CurStep = ssPostInstall  then
 begin
     ShellExec('', ExpandConstant('{app}\ServiceInstall.exe'),
                '-is AIS_server "'+ ExpandConstant('{app}\AIS_server.exe')+'"', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
 end;
end;

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
var
  ResultCode: Integer;
begin
  if CurUninstallStep = usUninstall then
    begin
       ShellExec('', ExpandConstant('{app}\ServiceInstall.exe'),
          '-u AIS_server "'+ ExpandConstant('{app}\AIS_server.exe')+'"', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
   end;
end;

//卸载程序的时候判断是否在运行
function InitializeUninstall(): Boolean;
begin
  begin
  //密码验证
  //Result :=  AskPassword();
  Result := TRUE;
//  DelTree(ExpandConstant('{app}\*'), False, True, True);
  end
end;

//提示卸载完后重启计算机
function UninstallNeedRestart(): Boolean;
begin
   Result := False;
   DelTree(ExpandConstant('{app}\*'), False, True, True);
   DelTree(ExpandConstant('{app}'), True, True, True);
end;

转载于:https://www.cnblogs.com/-yan/p/5017562.html

安装器---Inno Setup相关推荐

  1. inno setup将exe应用打包成——安装包

    文章目录 前言 一.打包exe文件 1.安装Inno setup 2.打包成安装包 二.测试安装包 前言 使用Inno setup应用来打包exe文件成安装包 提示:以下是本篇文章正文内容,下面案例可 ...

  2. Inno Setup 制作exe安装包

    Inno Setup 制作exe安装包 前言: 使用Inno Setup制作exe安装包,首先需要一个可运行的exe程序,然后下载Inno Setup工具,最后才是制作安装包的过程. exe主程序 此 ...

  3. inno setup基础使用教程

    前段时间我完成了几个软件的汉化,想把它们打包起来,可是苦于我是一个很菜的鸟,很笨的瓜,只好上网找关于安装程序制作的文章.不幸我没能找到:-( 没法只好自己去华军软件园里找找制作安装程序的软件,并一把下 ...

  4. inno setup详细使用教程

    inno setup详细使用教程 前段时间我完成了几个软件的汉化,想把它们打包起来,可是苦于我是一个很菜的鸟,很笨的瓜,只好上网找关于安装程序制作的文章.不幸我没能找到:-( 没法只好自己去华军软件园 ...

  5. Inno Setup 安装退出代码

    0 安装程序运行完成. 1 安装程序初始化失败. 2 用户在实际安装开始前单击向导页中的"取消",或在"这将安装-"消息框中选择了"否". ...

  6. 使用inno setup打包程序完整脚本(.net框架检测,重复安装检测)

    ; 脚本由 Inno Setup 脚本向导 生成!; 有关创建 Inno Setup 脚本文件的详细资料请查阅帮助文档! #define MyAppName "小小鸟软件"#def ...

  7. 用Inno Setup来解决.NetFramework安装问题

    前段时间朋友接了一个项目,具体是开发一个安装在局域网内的软件,这个软件会定时连接局域网内的服务器来更新本地客户端的一些信息,因为在局域网内存在着多种不同的Windows版本,从WindowsXP.Wi ...

  8. Inno Setup 系列之安装、卸载时调用bat

    需求 想在安装的时候调用install.bat,在卸载的时候调用uninstall.bat 解决 可以这样写 Inno Setup 的脚本: [Setup] ; NOTE: The value of ...

  9. 一键搞定Java桌面应用安装部署 —— exe4j + Inno Setup 带着JRE, 8M起飞

    转载自:http://www.blogjava.net/huliqing/archive/2008/04/18/193907.html 对于作Java桌面应用来说,比较烦人的就是安装部署问题,客户端是 ...

  10. Inno Setup 检测已安装的.NET Framework 版本

    翻译自:http://kynosarges.org/DotNetVersion.html 由 Jordan Russell 写的 Inno Setup 是一个伟大的安装脚本程序,但缺乏一个内置的函数来 ...

最新文章

  1. 在CentOS 6.8 x86_64上利用devtoolset搭建GCC 4.9.2和5.3.1开发环境
  2. 在Win7中安装Oracle 10g时检测报错的解决办法
  3. Cocos2d学习之路三(使用Zwoptex创建精灵表单和CCAnimate动画)
  4. VTK:规则多边形源用法实战
  5. Python实现双向链表
  6. mybatis plus 使用函数_mybatis-plus的使用 ------ 入门
  7. Hyper-V 2016 系列教程29 主流品牌服务器的BIOS的虚拟化相关设定
  8. 详解C++ friend关键字
  9. WCF中使用代理链技术恢复客户端代理层级
  10. 计算机主板图解内存插槽,图解电脑主板上的常见部件 -电脑资料
  11. 计算机232接口接线,RS232接口
  12. 报错解决——babel-preset-es2015 报错
  13. MapReduce各个执行阶段
  14. 【Derivation】采样定理证明
  15. Stata-交乘项专题: 主效应项可以忽略吗?
  16. 十人面试就我通过,只因我答对了这题TCP协议为什么需要三次握手
  17. eltable 无数据文案修改_写文案不断打磨修改,让你的文案简单易懂
  18. 数据分析师必备思维——矩阵思维
  19. Linux中mysql的重启
  20. 不用修改注册表和组策略也能在 Win11 报名教师资格证

热门文章

  1. 电信光猫dns服务器修改,电信光猫自动获取的DNS被修改,肿么改回来?
  2. 即拿即用-Android单线程断点下载
  3. 使用JMeter进行接口压力测试
  4. 接口压力测试神器Jmeter
  5. Camera 数据通路
  6. viper4android脉冲样本,V4A脉冲反馈样本第一弹 爽爆
  7. [Unity]存档功能
  8. 使用requests post请求爬取申万一级行业指数行情
  9. 微信红包架构设计,高并发系统应用实战
  10. GNS3模拟思科三层交换机(排错细节)