PRB: Programmatically Issuing Print Command May Not Print to Default Printer (283797)
The information in this article applies to:
- Microsoft Internet Explorer (Programming) 5.5
This article was previously published under Q283797 IMPORTANT: This article contains information about modifying the registry. Before you
modify the registry, make sure to back it up and make sure that you understand how to restore
the registry if a problem occurs. For information about how to back up, restore, and edit the
registry, click the following article number to view the article in the Microsoft Knowledge Base:
256986 Description of the Microsoft Windows Registry
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.
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.
RESOLUTIONWARNING: 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
REFERENCESFor more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:
Modification Type: | Major | Last Reviewed: | 12/15/2005 |
---|
Keywords: | kbnofix kbprb kbprint KB283797 |
---|
|