Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

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 "Browser Print Template" Vulnerability

↑ Back to the top


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.

↑ Back to the top


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.

↑ Back to the top


More information

Steps to Reproduce Behavior

  1. Create a new Standard EXE project in Visual Basic 6.0.
  2. Add the Microsoft Internet Controls component to the project.
  3. Add a WebBrowser control and a Button control to the form.
  4. Add the following to the code section of the project:
    Private Sub Command1_Click()
        WebBrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER, _
        "http://localhost/yourPrintTemplate.htm"
    End Sub
    
    Private Sub Form_Load()
        WebBrowser1.Navigate2 "http://www.microsoft.com/ms.htm"
    End Sub
    					
  5. Change the path of the print template so that it points to your print template.
  6. Run the project.
  7. Click the button to print the document. You receive an error message, which states that the program fails to print the document.

↑ Back to the top


References

For more information, refer to the following MSDN article:
Beyond Print Preview: Print Customization in Internet Explorer
http://msdn.microsoft.com/en-us/library/bb250434.aspx
For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:

↑ Back to the top


Keywords: KB308649, kbwebbrowser, kbprb

↑ Back to the top

Article Info
Article ID : 308649
Revision : 4
Created on : 5/11/2006
Published on : 5/11/2006
Exists online : False
Views : 660