Microsoft KB Archive/308649

= PRB: Cannot Use ExecWB to Print HTML Documents with Print Templates in Visual Basic =

Article ID: 308649

Article Last Modified on 5/11/2006

-

APPLIES TO


 * Microsoft Internet Explorer (Programming) 5.5 SP2
 * Microsoft Internet Explorer (Programming) 6.0
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual C++ 6.0 Enterprise Edition
 * Microsoft Visual C++ 6.0 Standard Edition
 * Microsoft Visual C++ 6.0 Professional Edition

-



This article was previously published under Q308649



SYMPTOMS
When you try to pass values to the third and fourth parameters of the WebBrowser control's ExecWB method, if the first parameter is OLECMDID=OLECMDID_PRINT, you may receive the following error message:

Run-time error '70': Permission Denied

After you install Internet Explorer 5.5 Service Pack 2 (SP2) or later, you can no longer use ExecWB to print Hypertext Markup Language (HTML) documents with print templates in Visual Basic or Visual C++. In addition, this problem occurs with Internet Explorer 5.5 SP1 after you install the security update that is available in the following Microsoft Knowledge Base article:

279328 Patch Available for &quot;Browser Print Template&quot; Vulnerability



CAUSE
As Q279328 describes, a vulnerability exists in this feature that enables a Web-based program to invoke a custom print template without permission from the user. This poses a security hazard because, by design, print templates are trusted code and thus are able to run ActiveX controls, even those controls that are not marked as safe for scripting.



RESOLUTION
There is currently no workaround to use ExecWB to pass a print template into the printing process because the action is not secure and presents a security hazard to the computer.

However, you can still use Visual C++ and the Exec method to parse in a print template to the print preview and print the document. You cannot achieve the same functionality in Visual Basic or in any scripts.



Steps to Reproduce Behavior
 Create a new Standard EXE project in Visual Basic 6.0. Add the Microsoft Internet Controls component to the project. Add a WebBrowser control and a Button control to the form.  Add the following to the code section of the project: Private Sub Command1_Click WebBrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER, _ &quot;http://localhost/yourPrintTemplate.htm&quot; End Sub

Private Sub Form_Load WebBrowser1.Navigate2 &quot;http://www.microsoft.com/ms.htm&quot; End Sub  Change the path of the print template so that it points to your print template. Run the project.</li> Click the button to print the document. You receive an error message, which states that the program fails to print the document.</li></ol>

<div class="references_section">