Scripts Thread, A little .vbs help please in Coding and Web Development; Morning to you all,
I use a small .vbs script to map printers on the network and it's been no ...
27th February 2009, 08:35 AM #1
A little .vbs help please
Morning to you all,
I use a small .vbs script to map printers on the network and it's been no problem for years. I've just changed a printer in school so altered the script accordingly, the new printer is there but so is the old one!!!!
heres the script
Set objNetwork = CreateObject("WScript.Network")
The only thing changed was xerox to photocopier.
Any Ideas would be welcomed
27th February 2009, 08:40 AM #2
delete the old one if its not in use and give it the same share name as the old one
Short of that you will need to enumerate all printers and remove them all before adding the new ones
27th February 2009, 08:41 AM #3
Are the old ones removed at any point? (otherwise it will stay ...)
27th February 2009, 08:47 AM #4
that was what I was going to do and I wish I had
Originally Posted by mac_shinobi
27th February 2009, 08:49 AM #5
Yes the printer was removed, I now have a feeling that it might be in the users profile somewhere.
Originally Posted by kmount
27th February 2009, 08:56 AM #6
This lovely bit of scripting below removes all existing network printers (leaves local - eg LPT and USB alone)... we use it to make sure that when users log on, they only get the printers we want them to have. Yes - printer connections do persist in user profile.
' WSH - Windows Logon Script
' Type and Target: Printers Logon Script for Workstations
' Location: King Edward VI Community College
' Compiled: August 2007
' Author: Stuart Wilkie
' Section 1: Error Handling and Variables
' 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
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
' Citrix specific section
if (Left(computerName, 5) = "svrts") then
computerName = LCase(WshShell.ExpandEnvironmentStrings("%CLIENTNAME%"))
3 Thanks to TheScarfedOne:
ICT_GUY (27th February 2009), ozzy (27th February 2009), SYNACK (27th February 2009)
27th February 2009, 08:56 AM #7
The old printer will be in the profile (either roaming or local cache) I found a bit of vbs yesterday that deletes all network printers which you can run before adding.
No written by me but publically available for free on the internet.
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer Where Network = TRUE")
For Each objPrinter in colInstalledPrinters
Oh I was beaten to it!
Thanks to IrritableTech from:
ozzy (27th February 2009)
27th February 2009, 08:58 AM #8
LOL - you can tell what time we all got to work today!! Logon - Edugeek, check posts! :-)
27th February 2009, 09:07 AM #9
- Rep Power
RUP's drag all of the printers you've added as that user everywhere.
See here; How to Alter Behavior of Printers That Roam with Roaming Profiles
I realise that 2k3 R2 has added some printer support, which is great, however we had already done this with vbs at login. We clear all non-local printers at user login, if the user is a member of staff they have a text file in their user area containing names of printers to be added (added via an HTA script they have access to), after this, regardless of staff/student, room/location specific printers are added via a csv file. There was some initial confusion but when they realised the benefits they were more than happy with the solution.
edit;Aww man, so many replies before I got a chance to finish my reply... I blame this shocking internet connection!
Last edited by itwasntme; 27th February 2009 at 09:10 AM.
27th February 2009, 09:07 AM #10
"LOL - you can tell what time we all got to work today!! Logon - Edugeek, check posts! :-)
By box_l in forum Scripts
Last Post: 12th August 2010, 12:35 AM
By RabbieBurns in forum Scripts
Last Post: 20th May 2008, 04:30 PM
By FN-GM in forum Scripts
Last Post: 18th May 2008, 07:30 PM
By bishopsgarthstockton in forum Web Development
Last Post: 12th July 2007, 08:44 AM
By meastaugh1 in forum Scripts
Last Post: 5th February 2007, 12:52 PM
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)