[windows2000] Re: print server migration

  • From: "Mark Lane" <marklanemail@xxxxxxxxx>
  • To: <windows2000@xxxxxxxxxxxxx>
  • Date: Tue, 19 Jul 2005 12:29:50 -0500

Hopefully someone has a prettier answer, but VBScript might help you.  Here
is a snippet of code I found that at least will get you started if you have
scripted before:
 
Function ChangePrintServer(strComputer,oldPrintServer,newPrintServer)
  Dim cntr, objPrinter, colInstalledPrinters, strDefaultPrinter,
strNewPrinter
  Dim WshNetwork, objWMIService
  Dim oPrinters
  On Error Resume Next
  cntr = 0
  strDefaultPrinter = GetDefaultPrinter(strComputer)
  'Wscript.Echo "Default printer is " & strDefaultPrinter
  Set WshNetwork = WScript.CreateObject("WScript.Network")
 
  Set oPrinters = WshNetwork.EnumPrinterConnections
  For i = 0 To oPrinters.Count - 1 Step 2
    If Left(oPrinters.Item(i),3) = "IP_" Then
      'Wscript.Echo "Network Printer: " & oPrinters.Item(i+1)
      If InStr(UCase(oPrinters.Item(i+1)),oldPrintServer) > 0 Then
        'Wscript.Echo "                 -needs change"
        cntr = cntr + 1
        PrinterList(cntr) = oPrinters.Item(i+1)
      End If
    End If
  Next
 
'WMI method only works in Windows 2000 and XP, not NT4.0
'  Set objWMIService = GetObject("winmgmts:" _
'  & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
'  Set colInstalledPrinters = objWMIService.ExecQuery _
'  ("Select * from Win32_Printer")
'  For Each objPrinter In colInstalledPrinters
'    'Wscript.Echo "Name: " & objPrinter.Name
'    If InStr(UCase(objPrinter.Name),oldPrintServer) > 0 Then
'      cntr = cntr + 1
'      PrinterList(cntr) = objPrinter.Name
'      'Wscript.Echo " Needs change, # and Name: " & cntr & " " &
PrinterList(cntr)
'    End If
'  Next
 
  Do Until cntr = 0
'Connect New Printer
    'Wscript.Echo "Shortname of " & PrinterList(cntr) & " is " &
ShortName(PrinterList(cntr))
    strNewPrinter = "\\" & newPrintServer & "\" &
ShortName(PrinterList(cntr))
    'Wscript.Echo "Adding " & strNewPrinter
    WshNetwork.AddWindowsPrinterConnection strNewPrinter
    If Err Then
      'Wscript.Echo "Could not add: " &Err.Number & Err.Description
      Err.Clear
    Else
'Reset If Default Printer
      If UCase(PrinterList(cntr)) = UCase(strDefaultPrinter) Then
        'Wscript.Echo "Setting " & strNewPrinter & " as default"
        WshNetwork.SetDefaultPrinter strNewPrinter
      End If
'Disconnect Old Printer
      WshNetwork.RemovePrinterConnection PrinterList(cntr), True
      If Err Then
        'Wscript.Echo "Could not remove " & PrinterList(cntr) & " " &
Err.Number & Err.Description
      End If
    End If
    cntr = cntr - 1
  Loop
End Function 
 
Function ShortName(FullName)
  Dim count4me
'  On Error Resume Next
  count4me = Len(FullName)
  If count4me = 0 Then
    ShortName = ""
    Exit Function
  End If
  Do Until Mid(FullName,count4me,1) = "\" Or count4me = 0 
    count4me = count4me - 1
  Loop 
  ShortName = Mid(FullName, count4me + 1, Len(FullName) - count4me)
End Function
 
Function GetDefaultPrinter(strComputer)
'
'  Const HKEY_CURRENT_USER = &H80000001
'  Const HKEY_LOCAL_MACHINE = &H80000002
  Dim WshShell, strValue, count4me, strPiece
'  Set StdOut = WScript.StdOut
 
Set WshShell = WScript.CreateObject("WScript.Shell")
strValue = WshShell.RegRead("HKCU\Software\Microsoft\Windows
NT\CurrentVersion\Windows\Device")

'WMI method only works in Windows 2000 and XP, not NT4.0
'  Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
'    strComputer & "\root\default:StdRegProv")
'  strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows"
'  strValueName = "Device"
'  oReg.GetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue
'  StdOut.WriteLine "Current Default Printer: " & strValue
  count4me = 1
  strPiece = Left(strValue,1)
  Do Until strPiece = "," Or count4me > Len(strValue)
    GetDefaultPrinter = GetDefaultPrinter & strPiece  
    count4me = count4me + 1
    strPiece = Mid(strValue,count4me,1)
  Loop
'  StdOut.WriteLine "Trimmed Current Default Printer: " & GetDefaultPrinter
End Function


-----Original Message-----
From: windows2000-bounce@xxxxxxxxxxxxx
[mailto:windows2000-bounce@xxxxxxxxxxxxx] On Behalf Of Dave stevens
Sent: Tuesday, July 19, 2005 4:13 AM
To: windows2000@xxxxxxxxxxxxx
Subject: [windows2000] print server migration


Hi Guys,
 
any input on this would be of great help.
 
We are looking to migrate our print server. More or less Like for like.
(windows 2000 SP4).
 
The only difference is that the server names will change.
 
I have used Microsoft's Print Migrator v3.1, which works a treat, if the
names of the server remain the same.
 
My question, is there a way to auto re-direct users installed printers to
the new server, without having to do a floor walk.
 
 
Thanks
 
Dave

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Other related posts: