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