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



The information in this article applies to:

  • Microsoft Internet Explorer (Programming) 5.5 SP2
  • Microsoft Internet Explorer (Programming) 6.0
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0
  • Microsoft Visual Basic Professional Edition for Windows 6.0
  • Microsoft Visual Basic Learning Edition for Windows 6.0
  • Microsoft Visual C++, 32-bit Enterprise Edition 6.0
  • Microsoft Visual C++, 32-bit Learning Edition 6.0
  • Microsoft Visual C++, 32-bit Professional Edition 6.0

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

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.

REFERENCES

For more information, refer to the following MSDN article: For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:

Modification Type:MajorLast Reviewed:5/11/2006
Keywords:kbprb kbWebBrowser KB308649