Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting Default Printer

Status
Not open for further replies.

zahead31

MIS
Jun 5, 2006
174
US
I am using a vb script to change the default printer, print a report, and set the default printer back to the original printer.

The printer I am trying to print to is a remote network printer that is connected through a Firebox. When the print job goes to print, the printer is idle and takes about thirty seconds to a minute to get to 'ready' status. Unfortunately, the print job usually times out.

Does anyone know how to have the script wait until the printer is 'ready' to fir the print job?

Here is the code I used to set the default printer (in case it helps):

Code:
set wshnetwork = createobject("wscript.network")

wshnetwork.setdefaultprinter "\\[i]servername[/i]\[i]printername[/i]"

Thanks in advance!
 
one of tsuji crypt'k scripts (i think) i am sure he does too many cross words :)

function setdefaultprtr(shost, prtrname)

'return zero for setting being successful
'else it shows the error number encountered.
defaultprtr=0 'error-less return
prtrname="" 'out-param
on error resume next
set svc=getobject("winmgmts:\\" & shost & "\root\cimv2")
set cprtr=svc.execquery("select name, attributes from win32_printer where name='" & prtrname & "'")
on error resume next
for each oprtr in cprtr
oprtr.attributes = oprtr.attributes or &h04
next
if err.number<>0 then setdefaultprtr=err.number : err.clear : prtrname=""
on error goto 0
set cprt=nothing : set svc=nothing

end function

or another copy and example of how to call the function..

prtrname = ""
defaultprtr "braits700c", prtrname
Msgbox prtrname

function defaultprtr(shost, prtrname)

defaultprtr=0 'error-less return
prtrname="" 'out-param
on error resume next
set svc=getobject("winmgmts:\\" & shost & "\root\cimv2")
set cprtr=svc.execquery("select name, attributes from win32_printer")
for each oprtr in cprtr
if (oprtr.attributes and &h04)=&h04 then prtrname=oprtr.name : exit for
next
if err.number<>0 then defaultprtr=err.number : err.clear : prtrname=""
on error goto 0
set cprt=nothing : set svc=nothing

end function
 
Thank you all for the replies, I will play around with this and see if I can get this to work!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top