Chuckster Posted July 30, 2008 Posted July 30, 2008 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("%CLIENTNAME%")) 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
Ric_ Posted July 31, 2008 Posted July 31, 2008 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.
Chuckster Posted September 4, 2008 Author Posted September 4, 2008 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.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now