Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - VBScript to print on secondary printer

Reply
 
Old 12-15-2008   #1 (permalink)
drhowarddrfine


 
 

VBScript to print on secondary printer

I have a script that goes out to the web, retrieves a web page, saves
it on the desktop and prints it. This works great with the default
printer but I need it to print on a secondary printer without changing
the default. Any ideas?
The only line that was changed from the working version is the one
after 'enable this to print'.

'define vars
dim officePrinter
officePrinter = "\\server\printer name"
url = "http://mysite.com"
path = "C:\Users\Store\Desktop\temp.txt"
'instantiate
Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
Set fso = CreateObject("Scripting.FileSystemObject")
Set txtfile = fso.OpenTextFile(path, 2, True)
Set oWS = WScript.CreateObject("WScript.Shell")
'make request
xmlhttp.open "GET", url, false
xmlhttp.send ""
'wait for response
xmlhttp.waitForResponse()
'if status is 200, then it's OK
if xmlhttp.status = 200 then
txtfile.WriteLine(xmlhttp.responseText)
txtfile.Close
'enable this to print
oWS.Run "notepad.exe /p " + path + " " + officePrinter
'enable this to just display
'oWS.Run "notepad.exe " + path
else
'popup bad response, or just omit to end
WScript.Echo("bad response")
end if
'destroy objects. I'm not sure this is necessary
Set txtfile = nothing
Set xmlhttp = nothing
Set oWS = nothing
Set fso = nothing


My System SpecsSystem Spec
Old 12-16-2008   #2 (permalink)
drhowarddrfine


 
 

Re: VBScript to print on secondary printer

Just found out that Windows is such a POS system that it doesn't allow
scripts to print to anything but the default printer. Unbelievable.
My System SpecsSystem Spec
Old 12-17-2008   #3 (permalink)
Tom Lavedas


 
 

Re: VBScript to print on secondary printer

On Dec 16, 7:24*pm, drhowarddrfine <robbel...@xxxxxx> wrote:
Quote:

> Just found out that Windows is such a POS system that it doesn't allow
> scripts to print to anything but the default printer. *Unbelievable.
Yes, but WMI allows you to reset which printer is the default in a
script. Then you can send your print job to the default and after the
job is done, it can be swapped back to the original. For example,
this code fragment saves the default printer's name and then sets the
default to another printer (assuming it is installed on that
machine) ...

Set oWMISrvc = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\.\root\cimv2")

Set cDfltPrinter = oWMISrvc.ExecQuery _
("Select * from Win32_Printer Where Default = True")

For Each objPrinter in cDfltPrinter
if objPrinter.Default then sDfltPtr = objPrinter.Name
Next

sAltPrtrName = "\\\\server\\printer"

Set cPrinter = oWMISrvc.ExecQuery _
("Select * from Win32_Printer Where Name = '" _
& sAltPrtrName & "'")

For Each oPrtr in cPrinter
oPrtr.SetDefaultPrinter()
Next

Set cDfltPrinter = oWMISrvc.ExecQuery _
("Select * from Win32_Printer Where Default = True")

For Each objPrinter in cDfltPrinter
if objPrinter.Default then sNewDfltPtr = objPrinter.Name
Next

wsh.echo "Default was", sOldDfltPtr
wsh.echo "Default is now", sNewDfltPtr

Just reverse the process to restore the original default after you
send the print job. SOme error detection is probably in order, but I
leave that to the you to work out.

Tom Lavedas
***********
http://there.is.no.more/tglbatch/

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
[MS Word Macro] VBscript flag image to not print it VB Script
HTML and VBscript printer management page VB Script
Powershell Wrapper Script Problems - Trying to Call PowershellExchange 2007 Commands from Secondary Language (Like VBScript) PowerShell
Vista Can't Print to Win2K shared printer-Test Print disappears fr Vista networking & sharing
Re: Print Shop won't print using laser printer Vista print fax & scan


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46