Page 1 of 1 1
Topic Options
#196881 - 2009-11-30 06:31 PM Want to switch to new print server
Gee Offline
Fresh Scripter

Registered: 2009-02-04
Posts: 48
Loc: illinois
We recently got a new print server. I was wondering how i would delete my existing printers that are pointing to my current print server and create printers that are mapped to my new print server. How would i script this?

Thanks,

Top
#196884 - 2009-11-30 07:36 PM Re: Want to switch to new print server [Re: Gee]
Gee Offline
Fresh Scripter

Registered: 2009-02-04
Posts: 48
Loc: illinois
Here is the printing part of the script. How would I delete the old print server and add to new server?

 Code:
Dim $Printers, $Printer
Dim $Drives, $Drive


$Printers = Split(''
	+ '\\OLD01\FIN'   + '|'
	+ '\\OLD01\MEM'   + '|'
	+ '\\OLD01\LJC2550PS3' + '|'
	+ '\\OLD01\LJC3800PS'  + '|'
	+ '\\OLD01\LJ4250NPS'  + '|'
	+ '\\OLD01\LJ4250TN'   + '|'
	+ '\\OLD01\LJ4250TN2'  + '|'
	+ '\\OLD01\LJ8100PCL6' + '|'
	+ '\\OLD01\LJ8100PS'   + '|'
	+ '\\OLD01\LJ4300PCL6' + '|'
	+ '\\OLD01\MCROPLXF24' + '|'
	+ '\\OLD01\OJ7310'     , '|')



;Installs printers for everybody.
	If @wksta <> 'OLD01'
		; Installing Printers...
		If InGroup("tech")
			 ?"Mailroom printer install"
			If PriMapState('\\OLD01\XWC120PS') = ''
				$RC = AddPrinterConnection('\\OLD01\XWC120PS')
			EndIf
		EndIf
		For Each $Printer in $Printers
				If PriMapState($Printer) = ''
					$RC = AddPrinterConnection($Printer)
				EndIf



; Do not forget to add the PriMapState UDF

function PriMapState($_Pri)
if @inwin=1
 if len(readvalue("HKCU\Software\Microsoft\Windows NT\CurrentVersion\Devices",$_Pri))
  if split(readvalue("HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows","Device"),",")[0]=$_Pri
   $PriMapState=2
  else
   $PriMapState=1
  endif
 endif
else
 dim $_Root,$_C,$_C2 $_Root="HKLM\System\CurrentControlSet\control\Print\Printers"
 for $_C=0 to 259
  $_C2=enumkey($_Root,$_C)
  If instr(READVALUE($_Root+"\"+$_C2,"Port"),$_Pri)
   If instr(READPROFILESTRING("%windir%\win.ini","windows","device"),$_Pri)
    $PriMapState = 2
   Else
    $PriMapState = 1
   Endif
  Endif
  if $_C2=259 $_C=$_C2 endif
 next
endif
[code] 
[/code]


Edited by amtagoran (2009-11-30 07:42 PM)

Top
#196885 - 2009-11-30 07:53 PM Re: Want to switch to new print server [Re: Gee]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
 Code:
$Printers = Split(''
+ '\\OLD01\FIN' + '|'
+ '\\OLD01\MEM' + '|'
+ '\\OLD01\LJ4300PCL6' + '|'
+ '\\OLD01\MCROPLXF24' + '|'
+ '\\OLD01\OJ7310' , '|')
is a kind of funky way of setting an array.. try this:
 Code:
$OldPrinters = '\\OLD01\FIN',
'\\OLD01\MEM',
'\\OLD01\LJC2550PS3',
'\\OLD01\LJC3800PS',
'\\OLD01\LJ4250NPS',
'\\OLD01\LJ4250TN',
'\\OLD01\LJ4250TN2',
'\\OLD01\LJ8100PCL6',
'\\OLD01\LJ8100PS',
'\\OLD01\LJ4300PCL6',
'\\OLD01\MCROPLXF24',
'\\OLD01\OJ7310'
Note how each line except the last simply ends with a comma. Also recognize that this defines an OldPrinters array!
Create a similar array for the new printers (called $Printers)

Modify your code to check for the presence of the old printer and delete it before mapping the new printer. The logic would be something like this
 Code:
If @wksta <> 'OLD01'
  ; Installing Printers...
  If InGroup("tech")
    'Mailroom printer install' ?
    If PriMapState('\\OLD01\XWC120PS') = ''
      $Rc = AddPrinterConnection('\\NEW01\XWC120PS')
    Else
      $Rc = DelPrinterConnection('\\OLD01\XWC120PS')
      $Rc = AddPrinterConnection('\\NEW01\XWC120PS')
    EndIf
  EndIf

  ; Delete Old Printer(s)
  For Each $Printer in $OldPrinters
    If PriMapState($Printer) <> ''
      $Rc = DelPrinterConnection($Printer)
    EndIf
  Next

  ; Add New Printer(s)
  For Each $Printer in $Printers
    If PriMapState($Printer) = ''
      $Rc = AddPrinterConnection($Printer)
    EndIf
  Next
EndIf
This is UNTESTED, and depends on both a $Printers and $OldPrinters array. You'll need to look at the PriMapState docs to determine if the If statement is correct for unmapping.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#196886 - 2009-11-30 07:55 PM Re: Want to switch to new print server [Re: Glenn Barnas]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Oh - and BTW - the CODE tags must be wrapped in square brackets ( [ & ] ), and the closing tag uses a forward slash (like HTML).

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#196888 - 2009-11-30 08:36 PM Re: Want to switch to new print server [Re: Glenn Barnas]
Gee Offline
Fresh Scripter

Registered: 2009-02-04
Posts: 48
Loc: illinois
I tried the code you suggested but is not deleting my old printers from the old server and the script is taking forever to execute. Any suggestions
Top
#196892 - 2009-11-30 09:02 PM Re: Want to switch to new print server [Re: Glenn Barnas]
Gee Offline
Fresh Scripter

Registered: 2009-02-04
Posts: 48
Loc: illinois
What am i doing wrong its not deleting my current printers its only adding the new printers.
Top
#196893 - 2009-11-30 09:44 PM Re: Want to switch to new print server [Re: Gee]
Gee Offline
Fresh Scripter

Registered: 2009-02-04
Posts: 48
Loc: illinois
Can I just see if my printers are connected from my old server, if so then delete and then add the new printers from my new server.
Top
#196897 - 2009-12-01 12:56 AM Re: Want to switch to new print server [Re: Gee]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Debugging 101 - Add some messages to the loop so you know what's happening. Sometimes you need to change the logic slightly to debug properly. Change the printer delete logic to
 Code:
  ; Delete Old Printer(s)
  For Each $Printer in $OldPrinters
    'Checking ' $Printer ' - '
    $PrintStatus = PriMapState($Printer)
    $PrintStatus 
    If $PrintStatus <> ''
      ' Deleting!'
      $Rc = DelPrinterConnection($Printer)
    EndIf
  Next
Glenn
_________________________
Actually I am a Rocket Scientist! \:D

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 693 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.061 seconds in which 0.028 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