Back to index
IE/VBScript printing
This snippet of VBScript forces Internet Explorer to print the
current page using the default printer, without displaying the
usual "print" dialog.
First, create a web browser control somewhere on the page:
<object id="WBControl" width="0" height="0"
classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></object>
Then, to print:
WBControl.ExecWB 6,2,3
For more information on what this actually does, check out
the WebBrowser control documentation here:
http://msdn.microsoft.com/workshop/browser/webbrowser/reflist_vb.asp
The parameters, in short:
-
6 = IDM_PRINT (i.e. print the current page)
-
2 = OLECMDEXECOPT_DONTPROMPTUSER (i.e. don't prompt)
-
3 = PRINT_DONTBOTHERUSER | PRINT_WAITFORCOMPLETION (self-explanatory)
Notes
-
Calling ExecWB from Javascript always produces the dialog -
anyone know why?
-
As far as I know there's no way of changing the printer used. The MSDN
link above refers to "custom print templates" but these aren't
accessible from VBScript - you'll need to embed a browser control
into a custom C++ app.
-
This technique won't work if IE's security settings stop the
control from being created.