On Dec 16, 7:24*pm, drhowarddrfine <robbel...@xxxxxx> wrote:
> 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/