I noticed on Wiki there was a script whereby you can print according to your room location.
I've adapted it and was wondering if anyone could have a look to see what I have done is right and correct me where I'm not. By the way, I've never dabbled in vbscript before and this is my first. I've tried it today but it didn't work. It didn't delete any of the current printers for a user and nor did it replace it with printers according to the room name.
Please help. Many thanks in advance.
' Script to add network printers to workstations and thin clients
' Author: Ric Charlton
' Declare variables and enumerate existing printer connections
On Error Resume Next
Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oPrinters = WshNetwork.EnumPrinterConnections
Dim computerName
computerName = LCase(WshNetwork.ComputerName)
' Delete existing connections to network printers
For i = 0 to oPrinters.Count - 1 Step 2
On Error Resume Next
if Left(oPrinters.Item(i), 3) <> "lpt" And Left(oPrinters.Item(i), 3) <> "usb" then
WshNetwork.RemovePrinterConnection oPrinters.Item(i+1), true, true
else WScript.Echo "No network printers found"
end if
Next
' Citrix specific section
if (Left(computerName, 5) = "svrts") then
computerName = LCase(WshShell.ExpandEnvironmentStrings("%CLIENTNA ME%"))
end if
I deleted this bit in bold but I got an error about the next command missing or something. Should I remove the next because we don't have a citrix here?
' Add printer connections dependant upon location
' Variable to select print server
Dim printServer
printServer = "MyFirstPrintServer"
Dim x
x = split(computerName,"-")
Select Case x(0)
I added this bit which replaced Select Case (Left(computerName, 4))
Case "room01"
WshNetwork.AddWindowsPrinterConnection "\\" & printServer & "\RM01-MONO"
WshNetwork.AddWindowsPrinterConnection "\\" & printServer & "\RM01-COLOUR"
WshNetwork.SetDefaultPrinter "\\" & printServer & "\RM01-MONO"
Case "room02"
WshNetwork.AddWindowsPrinterConnection "\\" & printServer & "\RM02-MONO"
WshNetwork.AddWindowsPrinterConnection "\\" & printServer & "\RM02-COLOUR"
WshNetwork.AddWindowsPrinterConnection "\\" & printServer & "\RM02-A3"
WshNetwork.SetDefaultPrinter "\\" & printServer & "\RM02-MONO"
End Select

You should be able to delete the Citrix section without a problem.
Could you paste in the errors you receive? (Run the script at the command prompt so you can copy and paste).
Could you also give us an example of your computer names so that we can check that you are inspecting them correctly.
Using the script I pasted earlier, how would you get it to map local printers that are either connected using a LPT1 connection or USB?
I think the script is kinda working but throws up errors when I try to add locally attached printers.
There are currently 1 users browsing this thread. (0 members and 1 guests)