`
yyzhpq
  • 浏览: 288236 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

创建可在网页下载安装的ActiveX控件(通过Setup.exe安装)

阅读更多
为完成网页自动下载并安装控件的功能,需要通过C#创建一个ActiveX控件,然后将该控件置于安装程序中,在打开网页的时候下载、安装并注册该ActiveX控件。本文是采用VS2005创建的,VS2003创建过程与之相似。

    首先,创建一个类库,为其命名为CreateActiveXEmail:

    删除掉默认生成的类Class1.cs,创建一个接口ActiveXEmailInterface:

 

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace CreateActiveXEmail
...{
    [Guid(
"CB5BDC81-93C1-11CF-8F20-00805F2CD064"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    
public interface ActiveXEmailInterface
    
...{
        
void GetInterfacceSafyOptions(int riid, out int pdwSupportedOptions, out int pdwEnabledOptions);
        
void SetInterfaceSafetyOptions(int riid, int dwOptionsSetMask, int dwEnabledOptions);
    }

}

    其中GUID可以通过【工具】-【创建GUID】来产生。

    实现该接口的目的就是提高程序的安全性,以便客户端IE在不更改设置的情况下可以预行该ActiveX控件。

    然后,用你需要实现某些功能的类来继承上面的接口。

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace CreateActiveXEmail
...{
    [Guid(
"060d1308-f34e-4c9f-8962-0abafe385d33"), ComVisible(true)]
    
public class ActiveXEmail : ActiveXEmailInterface
    
...{
        
public void GetInterfacceSafyOptions(int riid, out int pdwSupportedOptions, out int pdwEnabledOptions)
        
...{
            pdwSupportedOptions 
= 1;
            pdwEnabledOptions 
= 2;
        }


        
public void SetInterfaceSafetyOptions(int riid, int dwOptionsSetMask, int dwEnabledOptions)
        
...{
        }


        
public ActiveXEmail()
        
...{
        }

    }

}

 

    注意,上面代码中的类属性“ComVisible(true)”,是必须添加的。

    在上面的类中,仅仅是现实了接口的两个方法,至于其他需要的方法,自行添加即可。另外,需要对项目属性进行一点修改:

    注意,类属性中的“ComVisible(true)”和上图中的【为 COM Interop 注册】缺一不可!只有这样才能生成tlb文件。

    这样,一个可用的ActiveX控件就已经生成。在本机你可以随意调用其中的任何方法,但问题是,当客户端机器需要远程调用时,必须在能在客户端机器上注册该ActiveX控件才行。所以,还必须进行下面的步骤:将该ActiveX打包,在安装后在目标机器进行注册。

    创建一个安装包:

    然后右键单击项目,点击【添加】-【项目输出】,在【主输出】中选择上面创建的工程“CreateActiveXEmail”。然后,打开安装工程的【属性】页面,对项目的【安装URL】项进行设置:

注意,上图的【安装URL】项中,必须使用绝对路径。另外,上图中的“DllFolder”是一个已发布网站“http://172.16.11.136/TestingAX”下的一个目录,这意味着,当在客户端访问页面时,如果客户端未安装当前ActiveX控件,则从路径http://172.16.11.136/TestingAX/DllFolder”来下载。

    最后,在页面中按如下方法调用即可:

 

<object classid="clsid:060d1308-f34e-4c9f-8962-0abafe385d33"
               codebase
="DllFolder/setup.exe#version=1,0,0,0"></object>

 

 

另外,还可以采用其他方法,即上面的类库属性不选择【为 COM Interop 注册】,安装工程属性不为【安装URL】指定路径,类中也不添加“ComVisible(true)”属性,而是创建一个安装类:

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Reflection;
using System.IO;
using Microsoft.Win32;
using System.Diagnostics;

namespace CreateActiveXEmail
...{
    [RunInstaller(
true)]
    
public partial class CustomInstaller : Installer
    
...{
        
private string regCommandFile = string.Empty;
        
private string unRegCommandFile = string.Empty;

        
public CustomInstaller()
        
...{
            InitializeComponent();
        }


        
protected override void OnAfterInstall(System.Collections.IDictionary savedState)
        
...{
            
base.OnAfterInstall(savedState);

            
try
            
...{
                
//get the path of the Regasm.exe
                string regasmPath = string.Empty;

                
//get the path of the current executing assembly
                string currentAsmDLLFilePath = Assembly.GetExecutingAssembly().Location;
                
string currentAsmPath = currentAsmDLLFilePath.Substring(0, currentAsmDLLFilePath.LastIndexOf('\'+ 1);

                
string currentRegasmPath = string.Format("{0}{1}", currentAsmPath, "RegAsm.exe");
                
if (!File.Exists(currentRegasmPath))
                
...{
                    
try
                    
...{
                        RegistryKey frmReg 
= Registry.LocalMachine.OpenSubKey(@"SOFTWAREMicrosoft.NETFramework");
                        
if (frmReg == null)
                        
...{
                            
//the .net framework do not exist in the local machine
                            return;
                        }


                        
string frameworkVersion = Environment.Version.ToString();
                        frameworkVersion 
= frameworkVersion.Substring(0, frameworkVersion.LastIndexOf('.'));

                        regasmPath 
= string.Format(@"{0}v{1}{2}", frmReg.GetValue("InstallRoot").ToString(), frameworkVersion, "RegAsm.exe");

                        
if (!File.Exists(regasmPath))
                        
...{
                            
//the Regasm.exe do not exist in the local machine
                            return;
                        }

                    }

                    
catch (System.ArgumentException ex)
                    
...{
                        
throw new System.ArgumentException(ex.Message);
                    }

                }

                
else
                
...{
                    regasmPath 
= currentRegasmPath;
                }


                
//create the registration command line
                string regCommand = string.Format("{0} "{1}" /{2} /{3}", regasmPath, currentAsmDLLFilePath, "tlb""codebase");                
                
                
try
                
...{
                    regCommandFile 
= string.Format("{0}{1}", currentAsmPath, "Regasm.bat");
                    
if (File.Exists(regCommandFile))
                    
...{
                        File.Delete(regCommandFile);
                    }


                    
using (StreamWriter swReg = File.CreateText(regCommandFile))
                    
...{
                        swReg.Write(regCommand);
                        swReg.Flush();
                    }

                }

                
catch (UnauthorizedAccessException uaex)
分享到:
评论

相关推荐

    ffactivex-setup-r39.exe

    非IE内核支持activex控件,点击直接运行,然后在打开火狐浏览器,在地址栏里输入about:plugins检测是否安装成功

    TBarCode_Setup.msi

    TBarCode_Setup.msi 最好用的条形码activex控件,支持vb、vc、pb、。net等

    activex控件调用摄像头(能够直接安装使用)

    C#写的activex控件调用摄像头test.html能测试(先在setup2里的debug的msi直接安装)如果需要调用其他摄像头修改html里的document.getElementById('helloworld').start(0)这个0改为其他1或者2看你摄像头被列为几

    Web浏览器页面打印控件(ocx)

    即同一台电脑,在设置好打印参数后 A用户可以保存方案 "A3打印发票"(方案名称) 保存方案 "A5套打信封",......等 B用户可以保存方案 "李四A3打印发票"(方案名称) 保存方案 "李四A3套打",......等 保存后,下次...

    指纹开发包 指纹识别 指纹认证开发工具

    在安装驱动前不要将采集仪和PC连接,运行Setup.exe即可完成安装。 驱动程序完成后,将采集仪与PC连接,正常情况下,PC会发现新设备,如果系统提示重新启动 可选“否”,将采集仪拨下重插一次即可。 2、注册...

    ActiveX 控件工具集

    包含COMRaider_Setup、oleview、ShowActiveXInterface3个工具

    vc实例精通源码,windows基本控件的使用Demo

    03_ActiveXInDlg 在应用程序中使用ActiveX控件。 04_ActiveXInWeb 在浏览器中使用ActiveX控件。 05_MyActiveX3 在VC中显示动态的GIF动画。 06_RegOCX 在程序中注册和注销ActiveX控件。 第18章(\ Chapter...

    ff浏览器插件

    ocx控件是微软的,但是只能在ie上运行,通过ff-activex-host把ocx从ie上移植到chrome和火狐的浏览器上。

    CypHVAC VCL编程控件组 1.0

    CypHVAC ACTIVEX及VCL编程控件组,可以在程序中加入大量各种形式的暖通空调方面设备设备控件。目前提供各个控件的ACTIVEX 版本,能在支持ACTIVEX OCX控件的编程环境下使用,包括VB 6.0 ,VC 6.0,PB,DELPHI 6.0,...

    MFC类库详解中文版(chm)

    这个类允许ActiveX控件在后台下载属性数据时被激活 afxctl.h CDateTimeCtrl 封装新的日期/时间选取器控件 afxdtctl.h CDBException afxdb.h CDBVariant afxdb.h CDC afxwin.h CDialog 用于包含控件窗口的对话框...

    Open Drawing Alliance ActiveX Control

    To use the new control, run the setup.exe program, which will install and register DWGdirectX. Then add “OdaToolkit 1.0 Type Library” to your references list in VB.Improvements in This Release&#...

    ocx动态创建

    通过使用CreateControl方法动态图创建ocx控件,并利用GetControlUnknown等方法获取IDispatch指针, 采用 ATL 智能指针类调用 IDispatch 接口的方法和标准方式调用 IDispatch 接口的方法,使用activex控件,包括一个...

    C#版ActiveX + JS +Flex通讯 完整实现

    7:为了让ActiveX控件获得客户端的信任,控件类还需要实现一个名为“IObjectSafety”的接口。先创建该接口(注意,不能修改该接口的GUID值):(這里是直接copy網上的) using System; using System.Collections....

    VB6-SirkMini_2019.02.20 (1).rar

    除此之外还支持标准EXE、ActiveX EXE、Active DLL、ActiveX 控件、IDE插件等工程类型。  4、包含常用类库,编写程序更容易、更强大:VB6 原版完整控件、vbRichClient(支持多线程、dll免注册、高速2d绘图、物理引擎...

    MBAXP_Setup

    MODBUS控件 MBAXP_Setup 内有C++ #等范例

    新思微POS连锁超市管理系统(delphi源码控件)

    新思微POS连锁超市管理系统(delphi源码控件)(这次上传的是控件,方便大家学习与二次开发,请大家支持正版)POS收银系统.超市进销存管理系统.网络版.MSSQL2000★Delphi源码 │ ├─超市收银系统pos(无敌打印)for...

    如何查杀运行状态下的EXE、DLL病毒

     4)尝试以下操作方法:清空Temp文件夹→关闭打开的杀毒软件→换路径重新安装→把安装光盘中的安装目录拷贝到硬盘上,然后运行目录里的“Setup.exe”。  无法清除病毒怎么办?  1)先升级病毒库再杀毒;  2)用...

    步进电机控制程序

    如果出现提示dllregisterserver调用失败,可在程序 - 附件 - 命令提示符,在”命令提示符“上点击鼠标右键,选择”以管理员身份运行“命令, 这个时候将打开Dos命令窗口,然后按正常写法输入上述语句,就能够注册...

    lodop6 - web打印控件

    Lodop是专业Web打印控件,类型为ActiveX插件,用它既可裁剪输出页面内容, 又可用程序代码生成复杂打印页。该控件功能异常强大,却简单易用。 功能用JavaScript调用,主要接口函数如下: ● PRINT_INIT...

Global site tag (gtag.js) - Google Analytics