需要解决三个问题,运行环境检测与安装,按顺序执行安装,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. 将javascript函数写在Html标签里

    有些时候不想把函数写在script标签里了,想直接在html标签里直接加上js代码,可以这样写: <body onload="javascript:{window.location.h ...

  2. There are no resources that can be added or removed from the server

    第1步.新建一个“Dynamic Web Project” 第2步.把新建项目里面的.project文件和.settings文件夹复制到导入的那个项目里面. 第3步.把web projiect set ...

  3. 还原MySql数据库失败:max_allowed_packet 设置过小导致记录写入失败

    MySQL根据配置文件会限制Server接受的数据包大小. 有时候大的插入和更新会受 max_allowed_packet 参数限制,导致写入或者更新失败. 查看目前配置 show VARIABLES ...

  4. struts2 用if标签判断字符串包含

    String testStr = "用来判断是否包含的字符串"; <s:property value="testStr"/> <s:if te ...

  5. 使用iText对pdf做权限的操作(不允许修改,不允许复制,不允许另存为),并且加水印等

    添加水印,并且增加权限 @Test public void addWaterMark() throws Exception{ String srcFile="D:\\work\\pdf\\w ...

  6. Codeforces 696 D. Legen...

    Description 每个字符串有些价值,问生成长度为 \(l\) 的字符串最多能获得多少价值,总字符数不超过 \(200\), \(l\leqslant 10^{14}\) . Sol AC自动机 ...

  7. java27

    1:反射(理解)    (1)类的加载及类加载器    (2)反射:        通过字节码文件对象,去使用成员变量,构造方法,成员方法    (3)反射的使用        A:通过反射获取构造方 ...

  8. Effective Python2 读书笔记2

    Item 14: Prefer Exceptions to Returning None Functions that returns None to indicate special meaning ...

  9. js 获取元素宽高

    可以用源生js的.offsetHeight .offsetWidth属性 document.getElementById("temp_form").offsetHeight // ...

  10. linux编程问题记录

    1.程序中需要用到字符串的时候,尽可能选择string类型,这种类型的字符串有很多比较容易的功能,如字符串之间可以直接拷贝赋值 string a; string b="123"; ...