需要解决三个问题,运行环境检测与安装,按顺序执行安装,activex注册。

运行环境检测与安装

最开始的方法,百度之后,根据网上的搜索的结果,使用了
RegQueryDWordValue(HKLM, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{9A25302D-30C0-39D9-BD6F-21E6EC160475}', 'Version', version),最后的结果,我发现,跟我想的不一样,没有判断到是否已经安装了vc++9的环境,每次安装都会重复安装,最后,我发现,Uninstall中的GUID是不固定的,在不同的机器上面,安装之后,它会改变,原因不知。只好bings和google,
最后看了
http://blogs.msdn.com/b/astebner/archive/2010/10/20/10078468.aspx里面的How to detect the install state for the Visual C++ 2010 redistributable packages等文章,决定使用作者的办法。那就是调用msi.dll里面MsiQueryProductState函数。
我又在在传入值上面,又思考了半天,因为我用了作者提供的GUID号,返回值均为-2,而我的确已经安装了此产品了,我想可能是因为作者提供的产品GUID都与我手头上打包的x86.exe或者是x64.exe里面的产品GUID不一样,怎么看到这两个产品的GUID了,本人笨的很,只好装了一个wix的打包工具,解压缩这两个exe,然后,再看它们的wix格式的文件,最后在第一行看到了产品的GUID,跟作者提供的不一样,跟网上的那个GUID号也不一样。

静默安装

我在上面的文章里面看到了参数,不会用,最后查看了Exec的使用方法,才明白了,应该怎么写。

按顺序执行安装

开始写的是Files里面,自动注册activex,但结果经常会,运行环境还没有安装,就注册activex了,往往注册不成。
改为不让dll自动注册了,在安装完成之前,使用
RegisterServer(Is64BitInstallMode, ExpandConstant('{app}\SISSWebUKey.dll'), False);来进行注册。

整个安装打包文件如下

#define MyAppName "安全登录 for  IE (64)"
#define MyAppVersion "2.0.0.1"
#define MyAppPublisher "公司名"
#define MyAppURL "www.demo.com"
#define MyAppExeName "test.dll"

[Setup]
; 注: AppId的值为单独标识该应用程序。
; 不要为其他安装程序使用相同的AppId值。
; (生成新的GUID,点击 工具|在IDE中生成GUID。)
AppId={{CBA6F794-BD25-45A2-9A91-8F11C3A2E3BA}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DisableDirPage=yes
DefaultGroupName={#MyAppName}
DisableProgramGroupPage=yes
OutputDir=D:\work2013\projectInstallFile
OutputBaseFilename=SISSUKeySetup64
Compression=lzma
SolidCompression=yes
ArchitecturesInstallIn64BitMode=x64
PrivilegesRequired=admin
[code]
#IFDEF UNICODE
  #DEFINE AW "W"
#ELSE
  #DEFINE AW "A"
#ENDIF

function MsiQueryProductState(ProductCode: string): integer;
  external 'MsiQueryProductState{#AW}@msi.dll stdcall';
function MsiConfigureProduct(ProductCode: string;
  iInstallLevel: integer; eInstallState: integer): integer;
  external 'MsiConfigureProduct{#AW}@msi.dll stdcall';
var

HasRun:HWND;
var vc9SP1Missing: Boolean;
function InitializeSetup: Boolean;
var Path:string ;
ResultCode: Integer;
var
IniFile, OldString, NewString: string;
IniFileLines: TArrayOfString;
i: Integer;
currentIndex: Boolean;
var version: Cardinal;
begin
Result := true;
HasRun := FindWindowByClassName('IEFrame');
while HasRun<>0 do

begin

if MsgBox('安装程序检测到IE浏览器正在运行。' #13#13 '您必须先关闭它然后单击“是”继续安装,或按“否”退出!', mbConfirmation, MB_YESNO) = idNO then

begin

Result := false;

HasRun := 0;

end

else

begin

Result := true;

HasRun := FindWindowByClassName('IEFrame');

end;

end;
    //这里的GUID号需要自己查看下载的vcredist_x64.exe是否是此GUID
  if MsiQueryProductState('{DA5E371C-6333-3D8A-93A4-6FD5B20BCC6E}') <> 5 then begin
     vc9SP1Missing := true;
  end;
 
end;

procedure CurStepChanged(CurStep: TSetupStep);
 var
pt,IniFile, OldString, NewString: string;
IniFileLines: TArrayOfString;
ResultCode,i: Integer;
currentIndex: Boolean;
begin
  if (CurStep=ssPostInstall) then  
begin
   if(vc9SP1Missing=true) then
    begin
      pt:=  ExpandConstant('{tmp}\vcredist_x64.exe');//需要考虑返回值 0 ,是安装成功不需要重启 3010安装成功需要重启电脑 其它的是安装失败
     if( not Exec(pt,'/passive /norestart"','',SW_HIDE,ewWaitUntilTerminated,ResultCode)) then     
        begin
          MsgBox('C++运行环境安装失败,请手动安装!没有此控件,安全控件无法安装成功!', mbInformation, MB_OK);
        end;
    end;
end;
  if(CurStep=ssDone) then  
  begin
    RegisterServer(Is64BitInstallMode, ExpandConstant('{app}\test.dll'), False);
  end;
end;

function NeedInstallVC9SP1(): Boolean;
begin
  Result := vc9SP1Missing;
end;

function InitializeUninstall(): Boolean;
 var
 HasRun : Integer;
 begin
   Result := true;
   HasRun := FindWindowByClassName('IEFrame');
   while HasRun<>0 do

begin

if MsgBox('安装程序检测到IE浏览器正在运行。' #13#13 '您必须先关闭它然后单击“是”继续安装,或按“否”退出!', mbConfirmation, MB_YESNO) = idNO then

begin

Result := false;

HasRun := 0;

end

else

begin

Result := true;

HasRun := FindWindowByClassName('IEFrame');

end;

end;
   
 end;

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

[Files]
Source: "D:\work2013\projectOldKey64\NeedLib\vcredist_x64.exe"; DestDir: "{tmp}"; Check: NeedInstallVC9SP1
Source: "D:\work2013\projectOldKey64\SISSWebUKey\SISSWebUKey\Release\test.dll"; DestDir: "{app}"; Flags: promptifolder restartreplace
; 注意: 不要在任何共享系统文件上使用“Flags: ignoreversion”

[UninstallRun]
Filename: "regsvr32"; Parameters:"{app}\test.dll /u /s "
[UninstallDelete]
Type: files; Name:"{app}\test.dll"

如何用inno setup打包activex的更多相关文章

  1. Inno Setup 打包工具总结

    Inno Setup 打包工具总结 分类: Install Setup 2013-02-02 15:44 2386人阅读 评论(0) 收藏 举报 最近打包用到了Inno setup,在这个过程中容易犯 ...

  2. 使用Inno Setup 打包.NET程序,并自动安装.Net Framework

    使用Inno Setup 打包.NET程序,并自动安装.Net Framework http://www.cnblogs.com/xiaogangqq123/archive/2012/03/19/24 ...

  3. (Inno setup打包)检测系统是否已安装程序,若已安装则弹出卸载提示的代码

    原文 http://bbs.itiankong.com/thread-30983-1-5.html 有6天没研究pascal代码了,昨天晚上突然来了灵感,终于解决了苦思冥想好几天没能解决的问题, 因此 ...

  4. Inno Setup打包的程序提升为管理员权限

    Inno Setup打包的程序在Win7 64位系统上安装,安装步骤最后一步若选中运行程序,会跳出一个错误提示框. 这是因为64位win7系统运行程序时需要管理员权限,而打包的文件并没有这个权限就试图 ...

  5. Inno Setup打包添加和去除管理员权限

    原文:Inno Setup打包添加和去除管理员权限 添加管理员权限 1.在[Setup]节点添加 PrivilegesRequired=admin 2.进入安装目录,找到文件SetupLdr.e32, ...

  6. inno setup 打包exe程序

    inno setup 用于打包生成安装程序, 是通过的一个脚本 可以将 exe 执行文件以安装的形式,解压,添加依赖,创建快捷方式. 例如,我们写了个winform,我们怎么通过安装的形式,给客户的机 ...

  7. Inno Setup 打包的文件以管理员权限执行

    最近发现一个问题,就是Inno Setup打包的程序安装完毕后执行需求管理员权限的程序的时候会失败( inno createprocess   须要提升),解决问题的最简单办法就是打包的后的程序也以管 ...

  8. 【程序打包工具 Inno Setup】CreateProcess 失败:代码 740(Inno Setup打包的程序提升为管理员权限)

    原文参考 https://www.cnblogs.com/SnailProgramer/p/4243666.html http://blog.csdn.net/x356982611/article/d ...

  9. Inno Setup CreateProcess 失败:代码 740(Inno Setup打包的程序提升为管理员权限)

    原文参考 https://www.cnblogs.com/SnailProgramer/p/4243666.html http://blog.csdn.net/x356982611/article/d ...

随机推荐

  1. Aspose.Cells 导出 excel

    Aspose.Cells.Workbook book = new Aspose.Cells.Workbook(); Aspose.Cells.Worksheet sheet = book.Worksh ...

  2. nth-of-type

    ul li{ height:53px; line-height:53px; border-top:1px solid #e5e5e5;  display:block;color:#444;     } ...

  3. 安装配置LDAP遇到的问题

    问题1:安装完启动ldap服务报错: ldap: unrecognized service? 原因在于新版的openldap将服务名改为了slapd,使用service slapd start即可启动 ...

  4. POI导出excel日期格式

    参考帖子: [1]http://www.ithao123.cn/content-2028409.html [2]http://javacrazyer.iteye.com/blog/894850 再读本 ...

  5. MySQL的语句执行顺序

    MySQL的语句执行顺序 MySQL的语句一共分为11步,如下图所标注的那样,最先执行的总是FROM操作,最后执行的是LIMIT操作.其中每一个操作都会产生一张虚拟的表,这个虚拟的表作为一个处理的输入 ...

  6. js未定义判断

    if (typeof(homeType) == 'undefined') { //..... //..... } typeof函数判断,如果未定义的就会返回undefined,注意undefined ...

  7. django上传图片

    django修改头像的功能... 1.在表单中加入enctype="multipart/form-data: 关于表单中enctype的介绍:http://www.w3school.com. ...

  8. TCP协议三次握手和四次挥手

    http://www.cnblogs.com/rootq/articles/1377355.html TCP(Transmission Control Protocol) 传输控制协议 TCP是主机对 ...

  9. gcd推导

    欧几里得算法有性质: gcd(a, b)=gcd(b, a%b); 那么如何证明呢~ 法1: 我们先假设其成立并且有 gcd(a, b)=gcd(b, a%b)=d; a=k*b+c即a%b=c(我们 ...

  10. MongoDB replication set副本集(主从复制)(8)(转)

    转载地址:http://www.cnblogs.com/huangxincheng/p/4870557.html replicattion set 就是多台服务器维护相同的数据副本,提高服务器的可用性 ...