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: Programmatically Issuing Print Command May Not Print to Default Printer


Symptoms

In Internet Explorer 5.5, when you issue a print command, the print job may not be sent to the default system printer. This occurs whether you click Print on the File menu or if you call the ExecWB method of the WebBrowser control.

↑ Back to the top


Cause

When you select a printer in Internet Explorer (on the File menu, click Page Setup, click Printer, and choose a printer that is not the system default), your printer selection is stored in the following registry key:
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\PageSetup\printer
After you make this selection, Internet Explorer continues to use the printer value that is stored in the registry.

↑ Back to the top


Resolution

WARNING: If you use Registry Editor incorrectly, you may cause serious problems that may require you to reinstall your operating system. Microsoft cannot guarantee that you can solve problems that result from using Registry Editor incorrectly. Use Registry Editor at your own risk.

If you want to use the Microsoft Windows default printer when you host a WebBrowser control, you can use the code in this section to set this registry key to an empty string "", issue your print command, and then restore the value in the registry. Because there is no value under this key, Internet Explorer uses the default system printer.

NOTE: Make sure that you do not restore the registry value until after you are sure that the print job has finished; otherwise, you may restore the printer in the registry before Internet Explorer has actually read this key. This can occur when you print more complex Web pages.

To set the registry key to an empty string "", use the following Microsoft Visual Basic code:
    Dim wsh As Object
    Dim printer As String
    
    Const reg = "HKCU\Software\Microsoft\Internet Explorer\PageSetup\printer"
    
    Set wsh = CreateObject("WScript.Shell")
    
    printer = wsh.RegRead(reg)
    
    If Not printer = "" Then
        '   Clear the value
        wsh.RegWrite reg, ""
    End If

    wb.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER
    
    ' NOTE: Because Internet Explorer may not have read the registry key 
    ' yet, additional code may be required to ensure that Internet Explorer
    ' has read the registry key before you set it back to "".
    If Not printer = "" Then
        wsh.RegWrite reg, printer
    End If
    
    Set wsh = Nothing
				

↑ Back to the top


References

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

↑ Back to the top


Article Info
Article ID : 283797
Revision : 4
Created on : 1/1/0001
Published on : 1/1/0001
Exists online : False
Views : 150