Page 1 of 1 1
Topic Options
#204540 - 2012-03-22 02:57 PM Automated printer mapping based on existing
klink Offline
Just in Town

Registered: 2012-03-22
Posts: 3
Loc: Indiana
I need to change print servers and want to remap the new printers on the ne print server based on the existing printers mapped to the old print server. Sounds simple. I tried using the following from this site:

; "Adding Printers"
if primapstate("\\OldServer\printersharename")
$rc=addprinterconnection("\\newserver\printersharename")
endif
; "Removing Old Printers"
if primapstate("\\oldserver\printersharename")
$RC=delprinterconnection("\\oldserver\printersharename")
endif

This remaps all of the printers in the network to the workstation whether they exist as a mapped printer connection or not. What am I missing here?

Top
#204541 - 2012-03-22 03:08 PM Re: Automated printer mapping based on existing [Re: klink]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
Try your code with PrinterConnection()... it allows you to manage printers with the share name. With Primapstate you have to use the Printer Name.

PrinterConnection -
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=203840#Post203840

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
#204542 - 2012-03-22 03:40 PM Re: Automated printer mapping based on existing [Re: Allen]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
Ah, yes I did this a while ago for one of our subsidiaries.
I even retained the default printer, here's my code:
 Code:
Dim $arrDefaultPrinter, $strDefaultPrinter
$arrDefaultPrinter = ReadValue('HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows','Device')
If Instr($arrDefaultPrinter,",")
  $strDefaultPrinter = Split($arrDefaultPrinter,",")[0]
Else
  $strDefaultPrinter = $arrDefaultPrinter
EndIf

Dim $WSHNetwork, $objPrinters, $i, $strNewPrinter
$WSHNetwork = CreateObject("WScript.Network")
$objPrinters = $WSHNetwork.EnumPrinterConnections
For $i=0 To $objPrinters.Count -1
  If Instr($objPrinters.Item($i), "\\oldserver")
    $strNewPrinter = Join(Split($objPrinters.Item($i),"\\oldserver"),"\\newserver")
    $=DelPrinterConnection($objPrinters.Item($i))
    $=AddPrinterConnection($strnewPrinter)
    If $objPrinters.Item($i) = $strDefaultPrinter
      $=SetDefaultPrinter($strNewPrinter)
    EndIf
  EndIf
Next

Top
#204546 - 2012-03-22 08:20 PM Re: Automated printer mapping based on existing [Re: Arend_]
klink Offline
Just in Town

Registered: 2012-03-22
Posts: 3
Loc: Indiana
Allen
Tried PrinterConnection() and got same result. It is acting like it is ignoring the "If" and just running the add & remove whether the printer is mapped or not. I have tried a half dozen different ways and it always ignores the "If" and maps all of the printers. The OS is XP and I am testing on a VPC like I have in the past. I did this same thing with "If Ingroup" a couple of years ago, and it worked great, but I do not want to have to populate all of the groups again if I don't have to.

Top
#204547 - 2012-03-22 08:29 PM Re: Automated printer mapping based on existing [Re: klink]
klink Offline
Just in Town

Registered: 2012-03-22
Posts: 3
Loc: Indiana
Arend
Work perfectly. Thanx for the help.

Does anyone know why the workstation would be ignoring the If statement? Would like to know for future reference.

Top
#204548 - 2012-03-22 09:01 PM Re: Automated printer mapping based on existing [Re: klink]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
there is no way it will ignore an if.
you can do after the if line:
"yes, it is mapped"

and add else statement after the addprinter:
else
"no, it wasn't"

and after endif just do:
? " pause, what's the result" get $

this way you shall see, the code will do as expected.
_________________________
!

download KiXnet

Top
#204552 - 2012-03-23 09:31 AM Re: Automated printer mapping based on existing [Re: klink]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
 Originally Posted By: klink

...
Does anyone know why the workstation would be ignoring the If statement? Would like to know for future reference.


Stupid question You did include the PriMapState() UDF in your script right?
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

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
1 registered (mole) and 494 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.059 seconds in which 0.026 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