Microsoft KB Archive/283797

= PRB: Programmatically Issuing Print Command May Not Print to Default Printer =

Article ID: 283797

Article Last Modified on 5/21/2007

-

APPLIES TO


 * Microsoft Internet Explorer 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.



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 &quot;&quot;, 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 &quot;&quot;, use the following Microsoft Visual Basic code: Dim wsh As Object Dim printer As String Const reg = &quot;HKCU\Software\Microsoft\Internet Explorer\PageSetup\printer&quot; Set wsh = CreateObject(&quot;WScript.Shell&quot;) printer = wsh.RegRead(reg) If Not printer = &quot;&quot; Then '  Clear the value wsh.RegWrite reg, &quot;&quot; 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 &quot;&quot;. If Not printer = &quot;&quot; Then wsh.RegWrite reg, printer End If   Set wsh = Nothing

