Page 1 of 1 1
Topic Options
#203377 - 2011-10-25 11:15 PM if printer exists then
IMan Offline
Fresh Scripter

Registered: 2009-04-23
Posts: 15
Loc: California
What is the best way to map a printer if what i need to do is if a specific printer already exists on the users PC then add a new printer and delete the old one, But if the users doesnt have the printer then nothing happens.

Thanks,

Top
#203378 - 2011-10-25 11:42 PM Re: if printer exists then [Re: IMan]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4563
Loc: USA
Here is one way...

 Code:
? "Adding Printers"
if not primapstate("\\server1\draft")
  $rc=addprinterconnection("\\server1\draft")
endif
if not primapstate("\\server1\bond")
  $rc=addprinterconnection("\\server1\bond")
endif

? "Removing Old Printers"
if primapstate("\\server1\letters")
  $RC=delprinterconnection("\\server1\letters")
endif
if primapstate("\\server1\documents")
  $RC=delprinterconnection("\\server1\documents")
endif
if primapstate("\\server\hpletters")
  $RC=delprinterconnection("\\server\hpletters")
endif
if primapstate("\\server\hpdocuments")
  $RC=delprinterconnection("\\server\hpdocuments")
endif
if primapstate("\\server\lmdocuments")
  $RC=delprinterconnection("\\server\lmdocuments")
endif


PriMapState() - http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=83306#Post83306

How to use UDFs -
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=81943#Post81943

The rest of the UDFs are here -
http://www.kixtart.org/forums/ubbthreads.php?ubb=postlist&Board=7&page=1

Top
#203379 - 2011-10-26 12:21 AM Re: if printer exists then [Re: Allen]
IMan Offline
Fresh Scripter

Registered: 2009-04-23
Posts: 15
Loc: California
So will this do:

If printer1 exists, add printer2 and remove printer1
else
If Printer1 does not exist, quit.

Top
#203380 - 2011-10-26 12:29 AM Re: if printer exists then [Re: IMan]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4563
Loc: USA
 Code:
if primapstate("\\server1\printer1")
  $RC=delprinterconnection("\\server1\printer1")
  if not primapstate("\\server1\printer2")
    $RC=addprinterconnection("\\server1\printer2")
  endif
endif


Primapstate does all the work, it checks if it exists and saves the time of reinstalling drivers that are already there. You should consider using it for all your addprinterconnections.

Top
#203381 - 2011-10-26 12:41 AM Re: if printer exists then [Re: Allen]
IMan Offline
Fresh Scripter

Registered: 2009-04-23
Posts: 15
Loc: California
thanks for the help, im still having issues when if printer1 is not there its still mapping printer2 which i dont want. I only want it to map printer2 if printer1 exists, then it should remove printer1. Sorry, im still new at this.

Edited by IMan (2011-10-26 12:42 AM)

Top
#203382 - 2011-10-26 12:53 AM Re: if printer exists then [Re: IMan]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4563
Loc: USA
Unless I am completely missing something obvious, the code should work. I added some output so you can see what it is doing.

 Code:
if primapstate("\\server1\printer1")
  ? "Printer 1 Exists"
  ? "Removing Printer 1 - "
  $RC=delprinterconnection("\\server1\printer1")
  @serror
  if @error=0 and not primapstate("\\server1\printer2")
    ? "Adding Printer 2 - "
    $RC=addprinterconnection("\\server1\printer2")
    @serror
  endif
else
  ? "Printer 1 does not exist"
endif

Top
#203383 - 2011-10-26 01:13 AM Re: if printer exists then [Re: Allen]
IMan Offline
Fresh Scripter

Registered: 2009-04-23
Posts: 15
Loc: California
OK, i got it working, for some reason i had to remove the "not" from the following line:
if @error=0 and not primapstate("\\server1\printer2")
After that i tested it and it worked. Thanks for all the help.

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 2419 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.064 seconds in which 0.032 seconds were spent on a total of 13 queries. Zlib compression enabled.

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