#124496 - 2004-08-05 11:38 PM
Re: set local USB-Printer / LPT1:Printer... as default
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4562
Loc: USA
|
I am sure there are many ways to do this... here is one.
I wrote a UDF called PrinterList() which has an option to display the port the printer is running on. So the code could look something like the following (untested):
Code:
$printers=printerlist(,1)
$localprinter=0
$counter=0
while $localprinter=0 and $counter<=ubound($printers)
if left(split($printers[$counter],",")[1],3)="LPT"
$localprinter=1
$=setdefaultprinter(split($printers[$counter],",")[0])
endif
$counter=$counter+1
loop
if $localprinter=0
$=addprinterconnection("\\server\printer")
$=setdefaultprinter("\\server\printer")
endif
This could be all wrapped up in its own UDF but I'll leave that for you or someone else.
Edited by Al_Po (2004-08-05 11:46 PM)
|
|
Top
|
|
|
|
#124497 - 2004-08-06 12:26 PM
Re: set local USB-Printer / LPT1:Printer... as default
|
Burger_Reto
Fresh Scripter
Registered: 2004-08-05
Posts: 9
Loc: Luzern / Schweiz Switzerland
|
I have tried the following modified code . It works sometimes but unfortunately not always. The problem is, that all users / PC's habe the "printer" called "Microsoft Office Document Image Writer". I do not want to delete this "printer" but it may not be the defaultprinter. The Portname of the most USB-Printer called "DOT4_001"
Code:
$strComputer = "." $objWMIService = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2") $colItems = $objWMIService.ExecQuery("Select * from Win32_Printer",,48)
; Sleep 30
? 'Local Printer List' $count1 = 0 For Each $objItem in $colItems ? 'Printer Number: '+$count1 ? 'Printer PortName: '+$objItem.PortName
If $objItem.PortName = "LPT1:" SetDefaultPrinter ($ObjItem.Name) ? 'Error: '+@ERROR $DefaultPtr = "Set" EndIf If $objItem.PortName = "DOT4_001" SetDefaultPrinter ($ObjItem.Name) ? 'Error: '+@ERROR $DefaultPtr = "Set" EndIf $count1 = $count1 + 1 Next
? "Drucker verbunden "
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 429 anonymous users online.
|
|
|