65.9K
CodeProject 正在变化。 阅读更多。
Home

如何让 ActiveX 与 IE 受保护模式配合使用?

emptyStarIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

0/5 (0投票)

2013 年 4 月 26 日

CPOL

3分钟阅读

viewsIcon

27436

本文讨论如何在Internet Explorer保护模式下使用Dynamic Web TWAIN ActiveX控件。

引言

本文讨论如何在Internet Explorer保护模式下使用Dynamic Web TWAIN ActiveX控件。

背景

自从Windows Vista上的Internet Explorer 7发布以来,保护模式作为一项新的安全功能被引入。它基于Windows Vista的新的访问控制安全机制。在保护模式下运行时,Internet Explorer是一个低完整性进程,并且对用户系统的访问权限有限。

虽然保护模式更好地保护系统免受Internet的侵害,但是当ActiveX需要与高完整性对象通信时,它会导致问题。

Dynamsoft的Dynamic Web TWAIN是一款用于Web应用程序的文档扫描SDK。您可以将Dynamic Web TWAIN嵌入到您的网站中,以使用户能够在线扫描文档。它包括一个ActiveX版本,该版本允许用户在IE(x86 / x64)中从TWAIN兼容的扫描仪获取图像。在Windows Vista及更高版本上运行Dynamic Web TWAIN时,默认情况下会启用IE保护模式,因此用户始终会遇到以下问题

  • ActiveX无法访问连接到用户计算机的扫描仪
  • 由于权限不足,当ActiveX尝试从扫描仪获取图像时,IE崩溃

一种可能的解决方案是让最终用户手动关闭保护模式,以使ActiveX控件正常工作,但这不方便并且对用户不友好。

使用保护模式

为了解决保护模式引起的问题,Dynamsoft引入了一种新方法。Dynamic Web TWAIN没有在具有较低级别访问权限的浏览器进程下运行ActiveX,而是使用独立的代理进程与扫描仪进行通信,从而获得更好的兼容性和鲁棒性。代理进程具有中等级别的权限,因此它可以访问中等完整性对象。它具有以下优点

  • 避免因扫描仪驱动程序问题引起的浏览器崩溃,从而提高Web应用程序的鲁棒性。独立进程不会影响浏览器进程。
  • 用于扫描的独立进程比浏览器进程具有更高的权限级别。这可以解决扫描问题,例如浏览器无法成功访问扫描仪源,这是由Windows / IE的增强的安全功能引起的。

Using the Code

您可以简单地将BrokerProcessType属性设置为1,以启用单独的代理进程进行扫描。以下是在浏览器中使用Dynamic Web TWAIN进行ADF扫描(分辨率为100并使用灰色)的简单示例。

window.onload = DW_Pageonload;
function DW_PageonloadInner() {//Detect Environment
    // Get User Agent Value
    ua = (navigator.userAgent.toLowerCase());
 
    // Set the Explorer Type
    if (ua.indexOf("msie") != -1)
        DW_InIE = true;
    else
        DW_InIE = false;
 
    // Set the Operating System Type
    if (ua.indexOf("macintosh") != -1)
        DW_InWindows = false;
    else
        DW_InWindows = true;
 
    // Set the x86 and x64 type
    if (ua.indexOf("win64") != -1 && ua.indexOf("x64") != -1)
        DW_InWindowsX86 = false;
    else
        DW_InWindowsX86 = true;
}
 
function DW_CreateControl() {
    var objString = "";
    var DWTContainer;


    // For IE, render the ActiveX Object
    if (DW_InIE) {
        /*Only useful in version 8.* or earlier
        ///////////////////////////////////////
        objString = "<object classid='clsid:" + DW_PROCLASSID + "' style='display:none;'><param name='LPKPath' value='" + DW_LPKPath + "'/></object>";
        ///////////////////////////////////////
        */
        objString += "<object id='" + DW_ObjectName + "' style='width:" + DW_Width + "px;height:" + DW_Height + "px'";
 
        if (DW_InWindowsX86)
            objString += "codebase='" + DW_CABX86Path + "#version=" + DW_VersionCode + "' ";
        else
            objString += "codebase='" + DW_CABX64Path + "#version=" + DW_VersionCode + "' ";
 
        var temp = DW_IsTrial ? DW_TRAILCLASSID : DW_FULLCLASSID;
        objString += " classid='clsid:" + temp + "' viewastext>";
        objString += " <param name='Manufacturer' value='DynamSoft Corporation' />";
        objString += " <param name='ProductFamily' value='" + DW_ProductName + "' />";
        objString += " <param name='ProductName' value='" + DW_ProductName + "' />";
        //objString += " <param name='wmode' value='transparent'/>  ";
        objString += " </object>";
    }
    // For non-IE, render the embed object
    else {
        objString = " <embed id='" + DW_ObjectName + "'style='display: inline; width:" + DW_Width + "px;height:" + DW_Height + "px' id='" + DW_ObjectName + "' type='" + DW_MIMETYPE + "'";
        objString += " OnPostTransfer='Dynamsoft_OnPostTransfer' OnPostAllTransfers='Dynamsoft_OnPostAllTransfers'";
        objString += " OnMouseClick='Dynamsoft_OnMouseClick'  OnPostLoad='Dynamsoft_OnPostLoadfunction'";
        objString += " OnImageAreaSelected = 'Dynamsoft_OnImageAreaSelected'";
        objString += " OnImageAreaDeSelected = 'Dynamsoft_OnImageAreaDeselected'";
        objString += " OnMouseDoubleClick = 'Dynamsoft_OnMouseDoubleClick'";
        objString += " OnMouseRightClick = 'Dynamsoft_OnMouseRightClick'";
        objString += " OnTopImageInTheViewChanged = 'Dynamsoft_OnTopImageInTheViewChanged'";
        objString += " OnGetFilePath='Dynamsoft_OnGetFilePath'";
        if (DW_InWindows)
            objString += " pluginspage='" + DW_MSIPath + "'></embed>";
        else
            objString += " pluginspage='" + DW_PKGPath + "'></embed>";
    }
 
    DWTContainer = document.getElementById(DW_DWTContainerID);
    DWTContainer.innerHTML = objString;
    DWObject = document.getElementById(DW_ObjectName);
}
 
function DW_Pageonload() {
    DW_PageonloadInner();  //Detect environment
    InitInfo();            //Add guide info
    DW_CreateControl(); //Create an instance of the component in the DIV assigned by DW_DWTContainerID
 
    vShowNoControl = false; //By default, we assume the control is not loaded
    //Set interval to check if the control is fully loaded.
    DW_Seed = setInterval(DW_ControlDetect, 500);
}
 
// Check if the control is fully loaded.
 
function DW_ControlDetect() {
    // If the ErrorCode is 0, it means everything is fine for the control. It is fully loaded.
    if (DWObject.ErrorCode == 0) {
        /*Only useful in version 9.0 or later*/
        /////////////////////////////////////// Please put your product key below
        DWObject.ProductKey = "391243D92C15C4BE5C77E6EC25D16FC6D9754433530E517A67371A97AD158D173373ABC58E8272C940F1ACE1E97C953920000000";
        ///////////////////////////////////////
        DWObject.BrokerProcessType = 1; //scan in a separate brokerprocess
        DW_Pause();
        // For IE, attach events
        if (DW_InIE) {
            DWObject.attachEvent('OnPostTransfer', Dynamsoft_OnPostTransfer);
            DWObject.attachEvent('OnPostAllTransfers', Dynamsoft_OnPostAllTransfers);
            DWObject.attachEvent('OnMouseClick', Dynamsoft_OnMouseClick);
            DWObject.attachEvent('OnPostLoad', Dynamsoft_OnPostLoadfunction);
            DWObject.attachEvent('OnImageAreaSelected', Dynamsoft_OnImageAreaSelected);
            DWObject.attachEvent('OnMouseDoubleClick', Dynamsoft_OnMouseDoubleClick);
            DWObject.attachEvent('OnMouseRightClick', Dynamsoft_OnMouseRightClick);
            DWObject.attachEvent('OnTopImageInTheViewChanged', Dynamsoft_OnTopImageInTheViewChanged);
            DWObject.attachEvent('OnImageAreaDeSelected', Dynamsoft_OnImageAreaDeselected);
            DWObject.attachEvent('OnGetFilePath', Dynamsoft_OnGetFilePath);
        }
    }
    else {
        if (vShowNoControl == false) {
            DW_NoControl();
            vShowNoControl = true;
        }
    }
    DW_Timeout = setTimeout(function () { }, 10);
}
function DW_Pause() {
    clearInterval(DW_Seed);
}
 
function DW_NoControl() {
    // Display the message and hide the main control
    DW_CreateNonInstallDivPlugin();
    document.getElementById(DW_DWTNonInstallContainerID).style.display = "inline";
    document.getElementById(DW_DWTContainerID).style.display = "none";
}
function DW_CreateNonInstallDivPlugin() {
 
    var varHref = "";
    if (DW_InIE) {
        var ObjString = "<div style='display: block; border:solid black 1px; text-align:center; width:" + DW_Width + "px;height:" + DW_Height + "px'>";
        ObjString += "<ul style='padding-top:100px;'>";
        ObjString += "<li>The Component is not installed</li>";
        ObjString += "<li>You need to download and install the ActiveX to use this sample.</li>";
        ObjString += "<li>Please follow the instructions in the information bar.</li>";
        ObjString += "</ul></div>";
    }
    else {
        if (DW_InWindows) {
            if (location.hostname != "")
                varHref = "http://" + location.host + location.pathname.substring(0, location.pathname.lastIndexOf('/')) + "/" + DW_MSIPath;
            else
                varHref = DW_MSIPath;
        }
        else {
            if (location.hostname != "")
                varHref = "http://" + location.host + location.pathname.substring(0, location.pathname.lastIndexOf('/')) + "/" + DW_PKGPath;
            else
                varHref = DW_PKGPath;
        }
        var ObjString = "<div style='display: block; border:solid black 1px; text-align:center; width:" + DW_Width + "px;height:" + DW_Height + "px'>";
        ObjString += "<ul style='padding-top:100px;'>";
        ObjString += "<li>The Component is not installed</li>";
        ObjString += "<li>You need to download and install the plug-in to use this sample.</li>";
        ObjString += "<li>Please click the below link to download it.</li>";
        ObjString += "<li>After the installation, please RESTART your browser.</li>";
        ObjString += "<li><a href='" + varHref + "'>Download</a></li>";
        ObjString += "</ul></div>";
    }
    document.getElementById(DW_DWTNonInstallContainerID).innerHTML = ObjString;
}
function DW_AcquireImage() {
    DWObject.SelectSource(); //show the available devices
    DWObject.OpenSource();
    DWObject.IfShowUI = false; //hide the user interface of the TWAIN source
    DWObject.PixelType = 1; //scan images in gray
    DWObject.Resolution = 100; //set resolution to 100
    DWObject.IfFeederEnabled = true; 
    DWObject.XferCount = -1;
    DWObject.IfAutoFeed = true;    //auto feed
    DWObject.IfDisableSourceAfterAcquire = true;
    DWObject.AcquireImage();
}

当您运行嵌入Dynamic Web TWAIN的Web应用程序时,您将在任务管理器中看到用于扫描的代理进程

结论

通过在Dynamic Web TWAIN 9.0中使用独立的代理进程进行扫描,大大提高了Web扫描应用程序的安全性和鲁棒性。用户会发现更容易和更顺畅地激活和使用ActiveX控件,以便在更高版本的Windows IE上进行Web扫描。

有关Dynamic Web TWAIN的更多信息,请访问Dynamsoft网站

资源

Dynamic Web TWAIN是一个客户端Web扫描控件,您可以将其嵌入到您的Web应用程序中。它允许用户从TWAIN兼容的扫描仪扫描文档,或从数码相机获取图像。

Dynamic Web TWAIN支持Windows和Mac上的所有主流浏览器。

ActiveX版本 – 与x84 / x64 IE一起使用
插件版本 – 与Windows上的Chrome,Firefox,Safari,Opera一起使用
Mac版本 - 与Mac上的Chrome,Firefox,Safari,Opera一起使用

© . All rights reserved.