Page 1 of 1 1
Topic Options
#124495 - 2004-08-05 03:34 PM set local USB-Printer / LPT1:Printer... as default
Burger_Reto Offline
Fresh Scripter

Registered: 2004-08-05
Posts: 9
Loc: Luzern / Schweiz Switzerland
Hello

We have local USB-Printers or/and parallel-printer and some networkprinters. I need a kix-script that search for local printers (first USB, then LPT), and set it as the defaultprinter. If no localprinter is available, than it should define one of the networkprinters as the default.

Could someone help me???

Thanks
Reto


Edited by Burger_Reto (2004-08-05 08:15 PM)

Top
#124496 - 2004-08-05 11:38 PM Re: set local USB-Printer / LPT1:Printer... as default
Allen Administrator Offline
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 Offline
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
#124498 - 2004-08-06 07:07 PM Re: set local USB-Printer / LPT1:Printer... as default
Burger_Reto Offline
Fresh Scripter

Registered: 2004-08-05
Posts: 9
Loc: Luzern / Schweiz Switzerland
Thanks !

I have tried your scrip.
There is a error in the Line:
if left(split($printers[$counter],",")[1],3)="LPT"
ERROR : invalid method/function call: missing required parameter 2!

if I read your code correctly, the you serch only ports that begins with LPT. As I can find USB printers and exclude Adobe writer (is a "Printer" to)?

Thanks for your help!


Edited by Burger_Reto (2004-08-06 07:08 PM)

Top
#124499 - 2004-08-10 12:32 AM Re: set local USB-Printer / LPT1:Printer... as default
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
Not sure if the problem you were having had anything to do with this or not, but I had forgotten to dim $printerdesc in the printerlist() udf. The UDF has been updated.

As for how to look for USB, LPT, etc, just modify the code to include either a "select case" or a few ifs to look for those prefixes.

HTH

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 429 anonymous users online.
Newest Members
StuTheCoder, M_Moore, BeeEm, min_seow, Audio
17884 Registered Users

Generated in 0.054 seconds in which 0.025 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org