How to make ActiveX work with IE Protected Mode?
This article talks about how to use Dynamic Web TWAIN ActiveX control with Internet Explorer Protected Mode.
Introduction
This article talks about how to use Dynamic Web TWAIN ActiveX control with Internet Explorer Protected Mode.
Background
Since Internet Explorer 7 on Windows Vista was released, Protected Mode has been introduced as a new security feature. It is based on Windows Vista’s new access control security mechanism. When running in Protected Mode, Internet Explorer is a low integrity process and has limited permissions to access the user system.
While Protected Mode better protects the system from the Internet, it causes problems when ActiveX needs to talk with high integrity objects.
Dynamsoft’s Dynamic Web TWAIN is a document scanning SDK for web applications. You can embed Dynamic Web TWAIN in your website to enable users scan documents online. It includes an ActiveX edition which allows users to acquire images from TWAIN compatible scanners within IE (x86/x64). When running Dynamic Web TWAIN on Windows Vista and above, IE Protected Mode is on by default so users consistently get issues like the following:
- ActiveX failed to access the scanners connected to the user machine
- IE crashed when ActiveX tries to acquire images from scanner due to insufficient permissions
One possible solution is to have the end users manually turn off Protected Mode themselves in order to make ActiveX control work properly, but this is inconvenient and not user friendly.
Working with Protected Mode
To solve the issues caused by Protected Mode, Dynamsoft has introduced a new approach. Instead of running the ActiveX under the browser process, which has low level access, Dynamic Web TWAIN uses an independent broker process to communicate with the scanners for better compatibility and robustness. The broker process has medium level permission so it can access medium integrity objects. It has the following benefits:
- Avoid browser crashes caused by scanner driver problems, thus improving the robustness of the web application. The independent process will not affect the browser process.
- The independent process used for scanning has a higher permission level than the browser process. This can solve the scanning issues, such as browsers not accessing the scanner source successfully, caused by the increased security features of Windows/IE.
Using the Code
You can simply set the BrokerProcessType
Property to 1 to
enable separate broker process for scanning. Below is a simple sample of doing
ADF scanning, with resolution 100 and using gray color in browser using Dynamic
Web TWAIN.
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();
}
When you run the web application embedding Dynamic Web TWAIN, you will see the broker process for scanning in Task Manager:
Conclusion
By using an independent broker process for scanning in Dynamic Web TWAIN 9.0, it greatly improves the security and robustness of the web scanning application. And users will find it easier and smoother to activate and use the ActiveX control for web scanning on higher versions of IE on Windows.
For more information about Dynamic Web TWAIN, visit the Dynamsoft website.
Resources
Dynamic Web TWAIN is a client-side web scanning control which you can embed into your web application. It allows users to scan documents from TWAIN compatible scanners or acquiring images from digital cameras.
Dynamic Web TWAIN supports all the mainstream browsers on Windows and Mac.
ActiveX Edition – work with x84/x64 IE
Plugin Edition – work with Chrome, Firefox, Safari, Opera on Windows
Mac Edition - work with Chrome, Firefox, Safari, Opera on Mac