I have been onto a site recently, and had issues with the Group Policy Preferences not applying to the printers. I found out that this was due to the time it takes the printer to respond to the request to be “mapped” and made default.
I spent a few hours and hacked around some code and came up with this little masterpiece to allow multiple room printers to be added to the relevant OU based PC
‘—————Delete all Printers————————————————–
Dim wshNetwork, sPrintPath, clPrinters, i
Set wshNetwork = CreateObject(“WScript.Network”)
‘Remove Existing Printers
Set clPrinters = wshNetwork.EnumPrinterConnections
On Error Resume Next
For i = 0 to clPrinters.Count – 1 Step 2
wshNetwork.RemovePrinterConnection clPrinters.Item(i+1), true
Next
On Error Goto 0
‘—- For citrix script, un-comment following two lines:
‘Set Sh = CreateObject(“WScript.Shell”)
‘sys = Sh.ExpandEnvironmentStrings(“%CLIENTNAME%”) ‘sys= the returned workstation name (Citrix only)
‘—- For normal Windows machines un-comment the following line
sys = wshNetwork.ComputerName ‘sys = computer name (standard domain workstations – not citrix)
‘—- Note, you can’t have both of these uncommented!!!
‘User = CreateObject(“WScript.Network”).Username ‘ This returns the logged on username to variable: User
‘—————————————————————————————————————
CName = UCase(sys) ‘Get name from network object (Uppercase)
Set oNet = CreateObject(“WScript.Network”)
‘
‘ -=( Add printer and set a default based on computer name (CName) )=-
‘
‘ Test for Left(CName,NumberofChars)
‘ WEST BLOCK SCRIPTS
if Left(CName,3) = “W21” Then
oNet.AddWindowsPrinterConnection “\print-serverw21-mono”
oNet.AddWindowsPrinterConnection “\print-serverw21-colour”
oNet.SetDefaultPrinter “\print-serverw21-mono”
Elseif Left(CName,3) = “W22” Then
oNet.AddWindowsPrinterConnection “\print-serverw22-Mono”
oNet.AddWindowsPrinterConnection “\print-serverw22-Colour”
oNet.SetDefaultPrinter “\print-serverw22-mono”
etc etc
end IF