Best way to remap printers for 45 users in an AD environment?

Qualm

Gawd
Joined
May 31, 2003
Messages
562
I need to move all network printing from one server to another server in an Active Directory environment. The printer connections are currently defined in each users local profile on their machines.

I need to

1. Remove all current network printer mappings from local user profiles -

This I can do with WshNetwork.RemovePrinterConnection in the domain login script, HOWEVER there doesn't seem to be a way to check if the printer connection exists first?? Not all network printers currently exist in each user profile, they tend to have only the printers which are on their floor. If I try to remove a printer connection which doesn't exist, it gives an error, which I can't really have.

I was hoping there would be an easy way (the hard way is to EnumPrinterConnections and parse the result) to say "If this network printer connection exists, remove it" in Windows Scripting Host, but I can't seem to find it ...

2. Re-create all network printer mappings using the shared printers on the new server -

This I can do with WshNetwork.AddWindowsPrinterConnection in the domain login script, and I can use the optional paramter bUpdateProfile to make it part of the user's profile, but my question is should I? Is there a better way to define a set of network printer connections for all domain users in an Active Directory environment?

- Qualm
 
For my network, i use a program called con2prt.

http://www.ss64.com/nt/con2prt.html

works pretty well. combined with ifmember (resource kit file) you can set default printers based on groups. I just have con2prt disconnect from all printers and reconnect at logon. If a new printer is added, I just add the printer to the script or change the server location, etc.
 
Wouldn't install on my XP box. Haven't tried it on others but it does say it's a NT 4 workstation app off the MS download site
 
Don't install the ZAK :p

Con2prt.exe is a DOS mode app apparently, you can run it directly - I put a shortcut to "Con2prt.exe /f" on my desktop and it worked perfectly. It's in the \i386\tools folder once you unzip the zak.exe zipped file.
 
Here is what I use at work for scripting printers.

Code:
'Option Explicit
'On Error Resume Next

'=====================================================================
'
'
' NAME: @****** printer map
'
' Author: Jerrid
' DATE  : 8/3/2004
'
' COMMENT: <This script is to map specific printers to specific 
' computer OU's. 
' It deletes all existing network printers and then installs the 
' desired network 
' printer(s) and sets the default.  Local Printers are not deleted.
'====================================================================

Set oNetwork = WScript.CreateObject("WScript.Network")

'Remove only network printers

Set oOldPrinters = oNetwork.EnumPrinterConnections
For i = 0 to oOldPrinters.Count - 1
If mid(oOldPrinters.Item(i), 1, 2) = "\\" Then
sOldPrinterPath = oOldPrinters.Item(i)
oNetwork.RemovePrinterConnection sOldPrinterPath, True, True
End If
Next

'This script adds the @off printer and sets as default
'You Only need the SetDefaultPrinter option if you want more than 1 
'printer to 'connect, otherwise it can be commented out

	oNetwork.AddWindowsPrinterConnection"\\(server)\printer)"

        oNetwork.SetDefaultPrinter"\\(server)\(printer)"
 
When we remapped the printers for our users, I built an array of the old printer names and their new replacements.

I used the wscript network object method EnumPrinterConnections to enumerate their printers and built a second array consisting of those. Then I read the registry to determine the current default printer. HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device

I'd compare the printer array for the user to the substitution array, delete the printer if it matched the substitution, and then used the network objects AddWindowsPrinterConnection method to connect to the new printer (the true UNC works here). If it was the default printer, I'd use the SetDefaultPrinter method for the printer replacing the default.

There were two bits of wierdness.

One, on script host version 5.1 (Windows 2000 Pre IE 6.0), the net EnumPrinterConnections was a little flaky in some cases. I brute forced it by rerunning the method several times and checking to see if the value was zero, if it was, I'd rerun it up to ten times before letting it go on (normally it would work properly during the first 3 times, but it only cost about an additional .2 seconds so I overkilled it). I think this was related to the software build deployed in the field, rather than broken functionality in Windows Script host as I'd never seen that behavior before and I'd been using that function since the days of Script host version 4.0. (We replaced their previous vendor for a reason. Their build process was way out of control. <Shiver>.)

Two, printer names are tracked as the display name rather than the true UNC for already connected printers (unless they were specifically set to match by the admin, normally it matches the print driver name string of all things). If you do a "net view" of the print server, you will get the queue names that match the output.

Worked for our 2500 users.
 
Ok here's what I did. I didn't want to fool with EnumPrinterConnections, and I didn't read Jerrid's code for doing it that way until now.

I also wanted this to run only once per user/machine combination, on my network there are several users who move between machines and there are several machines which have a generic "placeholder" network login (named "placeholder" :p). So I stuck a "If file exists" test in there, with the dummy file stored in C:\Documents and Settings\userprofile.

This is a hybrid solution, mixing the Con2prt.exe utility and a windows script. I'm going to stick it in the system log script for a while, until I'm pretty sure all users have logged on to all the machines they normally use and the printers have been updated.


Code:
Dim fs
Set fs = WScript.CreateObject("Scripting.FileSystemObject")

Set WshShell = CreateObject("WScript.Shell")
u = "%USERPROFILE%"
t = WshShell.ExpandEnvironmentStrings(u) & "\MovePrinterstoERS7Done.txt"
s = "F:\Apps\Print\MovePrinterstoERS7Done.txt"

If fs.FileExists(t) then

   ' Already done, but I might want to do something here in the future

Else

  MsgBox("Redefining printers to server ERS7. If this takes more than 5 minutes, or you get an error, please call Greg.")  

  Set WshShell = WScript.CreateObject("WScript.Shell")
  WshShell.Run "F:\Apps\Print\Con2prt.exe /f "  'removes all current network printer connections

  Set WshNetwork = CreateObject("WScript.Network")
  WshNetwork.AddWindowsPrinterConnection "\\ERS7\OHIO", true, true
  WshNetwork.AddWindowsPrinterConnection "\\ERS7\ALASKA", true, true
  ' ... other printers

  fs.CopyFile s, t   'copies a file to serve as an indicator that the printers were moved to ERS7

  MsgBox("Printers for your user profile have been successfully redefined to ERS7. Please select your Default Printer now. If you experience problems printing, please call Greg.")

End If
 
Back
Top