Page 1 of 1 1
Topic Options
#187175 - 2008-04-22 08:46 PM Move Printer Server
SnoopDuJour Offline
Just in Town

Registered: 2008-04-22
Posts: 3
I am only using a snipit from this script.
I have modified the script, as it was installing ALL printers from the [PRINTER_MAP].

One printer does not want to be moved.

Here is the script.
--------
$pmap="\mitt_printers2.ini"
For Each $key In Split(ReadProfileString($pmap,"PRINTER_MAP",""),Chr(10))
If PriMapState($key)
$nulp=AddPrinterConnection(ReadProfileString($pmap,"PRINTER_MAP",$key))
If PriMapState($key)=2
$nulp=SetDefaultPrinter(ReadProfileString($pmap,"PRINTER_MAP",$key))
EndIf
$nulp=DelPrinterConnection($key)
EndIf
Next
------------------------------

This is my mitt_printers2.ini file


[PRINTER_MAP]
\\kcmakiki\MITTiR3035=\\TRPRINT\MITTRMIIR3035

---
Thanks


Edited by SnoopDuJour (2008-04-22 08:47 PM)

Top
#187176 - 2008-04-22 09:29 PM Re: Move Printer Server [Re: SnoopDuJour]
ghangis Offline
Just in Town

Registered: 2008-04-21
Posts: 4
Loc: canada
Gents, I'm trying to use this script and I can't for the life of me get it working... My situation is very similar here... migrating printers from serverA to serverB and I want the script to check if \\serverA\printer1 exists, if it does, map \\serverB\printer1 (same share name).

if someone could assist I would be muchly greatful

Cheers,

Top
#187178 - 2008-04-22 10:31 PM Re: Move Printer Server [Re: ghangis]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Hello Ghangis,

You should not Hijack someone else post. You should post your own post and reference this one if needed.

ALL - I moved this thread out of the Learning Series into the BASIC forum.
It is in reference to the post here:
Move Print Server

Top
#187179 - 2008-04-22 10:36 PM Re: Move Printer Server [Re: SnoopDuJour]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Snoop,

You should not modify a UDF. They are designed to operate exactly as coded and you will find that unless they are broken most of us won't spend the time to help you clean up your code to make it work when that is what the UDF is for in the first place.

Please explain in more detail why or how you think the UDF is adding printers that are not already found on the system so we can help see what might be going on.

I've used the UDF in production so I know first hand that it does work so we just need to help you maybe with how you're coding or understanding it.

Top
#187282 - 2008-04-24 10:36 PM Re: Move Printer Server [Re: ghangis]
SnoopDuJour Offline
Just in Town

Registered: 2008-04-22
Posts: 3
 Originally Posted By: ghangis
Gents, I'm trying to use this script and I can't for the life of me get it working... My situation is very similar here... migrating printers from serverA to serverB and I want the script to check if \\serverA\printer1 exists, if it does, map \\serverB\printer1 (same share name).

if someone could assist I would be muchly greatful

Cheers,


If your just changing the server name, here is a VB Script which works Perfectly for me (when the share names are the same)

:VBcode

Option Explicit
Dim from_sv, to_sv, PrinterPath, PrinterName, DefaultPrinterName, DefaultPrinter
Dim DefaultPrinterServer, SetDefault, key
Dim spoint, Loop_Counter
Dim WshNet, WshShell
Dim WS_Printers
DefaultPrinterName = ""
spoint = 0
SetDefault = 0
set WshShell = CreateObject("WScript.shell")

from_sv = "\\OldPrintServerName" 'This should be the name of the old server.
to_sv = "\\NewPrintServerName" 'This should be the name of your new server.

'Just incase their are no printers and therefor no defauld printer set
' this will prevent the script form erroring out.
On Error Resume Next
key = "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device"
DefaultPrinter = LCase(WshShell.RegRead (key))
If Err.Number <> 0 Then
DefaultPrinterName = ""
else
'If the registry read was successful then parse out the printer name so we can
' compare it with each printer later and reset the correct default printer
' if one of them matches this one read from the registry.
spoint = instr(3,DefaultPrinter,"\")+1
DefaultPrinterServer = left(DefaultPrinter,spoint-2)
if DefaultPrinterServer = from_sv then
DefaultPrinterName = mid(DefaultPrinter,spoint,len(DefaultPrinter)-spoint+1)
end if
end if
Set WshNet = CreateObject("WScript.Network")
Set WS_Printers = WshNet.EnumPrinterConnections
'You have to step by 2 because only the even numbers will be the print queue's
' server and share name. The odd numbers are the printer names.
For Loop_Counter = 0 To WS_Printers.Count - 1 Step 2
'Remember the + 1 is to get the full path ie.. \\your_server\your_printer.
PrinterPath = lcase(WS_Printers(Loop_Counter + 1))
'We only want to work with the network printers that are mapped to the original
' server, so we check for "\\Your_server".
if LEFT(PrinterPath,len(from_sv)) = from_sv then
'Now we need to parse the PrinterPath to get rhe Printer Name.
spoint = instr(3,PrinterPath,"\")+1
PrinterName = mid(PrinterPath,spoint,len(PrinterPath)-spoint+1)
'Now remove the old printer connection.
WshNet.RemovePrinterConnection from_sv+"\"+PrinterName
'and then create the new connection.
WshNet.AddWindowsPrinterConnection to_sv+"\"+PrinterName
'If this printer matches the default printer that we got from the registry then
' set it to be the default printer.
if DefaultPrinterName = PrinterName then
WshNet.SetDefaultPrinter to_sv+"\"+PrinterName
end if
end if
Next
Set WS_Printers = Nothing
Set WshNet = Nothing
Set WshShell = Nothing

Top
#187294 - 2008-04-25 11:12 AM Re: Move Printer Server [Re: SnoopDuJour]
Björn Offline
Korg Regular
*****

Registered: 2005-12-07
Posts: 953
Loc: Stockholm, Sweden.
There's a ton of KiX-code here, as udf's and prepped and ready to go scripts-snippets, just search for it.
_________________________
as long as it works - why fix it?
If it doesn't work - kix-it!

Top
#187368 - 2008-04-28 04:51 PM Re: Move Printer Server [Re: Björn]
ghangis Offline
Just in Town

Registered: 2008-04-21
Posts: 4
Loc: canada
wow, that's a lot of code. I appreciate the assistance, but how do I implement?? do I just append that to the existing kix script??

thanks again.

Top
#187375 - 2008-04-28 11:49 PM Re: Move Printer Server [Re: ghangis]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Here is the code that we recently used to migrate everyone from one print server to two print servers (clustered enviroment to boot)

 Code:
$Printer = ReadValue("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows", "Device")
$Server = Split($Printer,"\")
$sPrinterShare = Split($Server[3],",")

$PrinterName = $sPrinterShare[0]
$OldServerName = $Server[2]
If $Server[2] = "NewServer1" Or
   $Server[2] = "NewServer2"
	Goto additional
Else
	Select
	Case Right($sPrinterShare[0],1)=1
	$NewServerName="NewServer1"
	Case Right($sPrinterShare[0],1)=3
	$NewServerName="NewServer1"
	Case Right($sPrinterShare[0],1)=5
	$NewServerName="NewServer1"
	Case Right($sPrinterShare[0],1)=7
	$NewServerName="NewServer1"
	Case Right($sPrinterShare[0],1)=9
	$NewServerName="NewServer1"
	Case 1
	$NewServerName="NewServer2"
	EndSelect
EndIf

$OldValue = "\\"+$OldServerName+"\"+$PrinterName
$NewValue = "\\"+$NewServerName+"\"+$PrinterName
$rc=DelPrinterConnection("$OldValue")=0
$rc=AddPrinterConnection("$NewValue")=0

:additional
Dim $iIndex, $sPrinterkey[]
$iIndex = 0

While @ERROR=0
	ReDim Preserve $sPrinterkey[$iIndex]
	$sPrinters="HKCU\Printers\Connections"
	$sPrinterKey[$iIndex] = EnumKey($sPrinters,$iIndex)
$iIndex=$iIndex+1
Loop

For Each $ in $sPrinterkey
$OldServerName=Split($,",")[2]
If $<>"" 
	If Split($,",")[2] = "NewServer1" Or
		Split($,",")[2] = "NewServer2"
		Exit
	Else
		Select
		Case Right(Split($,",")[3],1)=1
		$NewServerName="NewServer1"
		Case Right(Split($,",")[3],1)=3
		$NewServerName="NewServer1"
		Case Right(Split($,",")[3],1)=5
		$NewServerName="NewServer1"
		Case Right(Split($,",")[3],1)=7
		$NewServerName="NewServer1"
		Case Right(Split($,",")[3],1)=9
		$NewServerName="NewServer1"
		Case 1
		$NewServerName="NewServer2"
		EndSelect
	EndIf
		$OldValue = "\\"+$OldServerName+"\"+Split($,",")[3]
		$NewValue = "\\"+$NewServerName+"\"+Split($,",")[3]
		$rc=DelPrinterConnection("$OldValue")=0
		$rc=AddPrinterConnection("$NewValue")=0
EndIf
Next
	



If you look at the code you will notice that all of our printers end with a Numeric Digit, and that is how we decide what server the printer share would reside on.
_________________________
Today is the tomorrow you worried about yesterday.

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 (Allen) and 382 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.064 seconds in which 0.031 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