+ Post New Thread
Results 1 to 10 of 10
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 ...
  1. #1
    ozzy's Avatar
    Join Date
    Oct 2007
    Posts
    260
    Thank Post
    39
    Thanked 39 Times in 36 Posts
    Rep Power
    21

    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")
    objNetwork.AddWindowsPrinterConnection "\\europa\itlaser"
    objNetwork.AddWindowsPrinterConnection "\\europa\xerox"
    objNetwork.SetDefaultPrinter "\\europa\xerox"

    The only thing changed was xerox to photocopier.
    Any Ideas would be welcomed
    Ozzy

  2. #2

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,763
    Thank Post
    3,273
    Thanked 1,053 Times in 974 Posts
    Rep Power
    365
    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

  3. #3


    Join Date
    Feb 2007
    Location
    Northamptonshire
    Posts
    4,691
    Thank Post
    352
    Thanked 796 Times in 715 Posts
    Rep Power
    347
    Are the old ones removed at any point? (otherwise it will stay ...)

  4. #4
    ozzy's Avatar
    Join Date
    Oct 2007
    Posts
    260
    Thank Post
    39
    Thanked 39 Times in 36 Posts
    Rep Power
    21
    Quote Originally Posted by mac_shinobi View Post
    delete the old one if its not in use and give it the same share name as the old one
    that was what I was going to do and I wish I had

  5. #5
    ozzy's Avatar
    Join Date
    Oct 2007
    Posts
    260
    Thank Post
    39
    Thanked 39 Times in 36 Posts
    Rep Power
    21
    Quote Originally Posted by kmount View Post
    Are the old ones removed at any point? (otherwise it will stay ...)
    Yes the printer was removed, I now have a feeling that it might be in the users profile somewhere.

  6. #6
    TheScarfedOne's Avatar
    Join Date
    Apr 2007
    Location
    Plymouth, Devon
    Posts
    1,288
    Thank Post
    605
    Thanked 160 Times in 145 Posts
    Blog Entries
    78
    Rep Power
    83
    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.

    Code:
    ' 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
    
    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 
    
                end if
    
    Next
    
    
    
    ' Citrix specific section
    
    if (Left(computerName, 5) = "svrts") then
    
    	computerName = LCase(WshShell.ExpandEnvironmentStrings("%CLIENTNAME%"))
    
    end if

  7. 3 Thanks to TheScarfedOne:

    ICT_GUY (27th February 2009), ozzy (27th February 2009), SYNACK (27th February 2009)

  8. #7
    IrritableTech's Avatar
    Join Date
    Nov 2007
    Location
    West Yorkshire
    Posts
    800
    Thank Post
    84
    Thanked 174 Times in 143 Posts
    Rep Power
    65
    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.

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

    Set colInstalledPrinters = objWMIService.ExecQuery _
    ("Select * from Win32_Printer Where Network = TRUE")

    For Each objPrinter in colInstalledPrinters
    objPrinter.Delete_
    Next
    No written by me but publically available for free on the internet.

    [edit]Oh I was beaten to it!

  9. Thanks to IrritableTech from:

    ozzy (27th February 2009)

  10. #8
    TheScarfedOne's Avatar
    Join Date
    Apr 2007
    Location
    Plymouth, Devon
    Posts
    1,288
    Thank Post
    605
    Thanked 160 Times in 145 Posts
    Blog Entries
    78
    Rep Power
    83

    Lightbulb

    LOL - you can tell what time we all got to work today!! Logon - Edugeek, check posts! :-)

  11. #9

    Join Date
    Apr 2008
    Posts
    64
    Thank Post
    10
    Thanked 2 Times in 2 Posts
    Rep Power
    13
    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 08:10 AM. Reason: aww

  12. #10
    ozzy's Avatar
    Join Date
    Oct 2007
    Posts
    260
    Thank Post
    39
    Thanked 39 Times in 36 Posts
    Rep Power
    21
    "LOL - you can tell what time we all got to work today!! Logon - Edugeek, check posts! :-)
    Sad eh

SHARE:
+ Post New Thread

Similar Threads

  1. vbs logon with ie
    By box_l in forum Scripts
    Replies: 5
    Last Post: 11th August 2010, 11:35 PM
  2. small vbs help please
    By RabbieBurns in forum Scripts
    Replies: 4
    Last Post: 20th May 2008, 03:30 PM
  3. Sub within a sub - VBS Script
    By FN-GM in forum Scripts
    Replies: 5
    Last Post: 18th May 2008, 06:30 PM
  4. Would like to learn VBS
    By bishopsgarthstockton in forum Web Development
    Replies: 11
    Last Post: 12th July 2007, 07:44 AM
  5. ResetAccountsAdminSDHolder.vbs
    By meastaugh1 in forum Scripts
    Replies: 1
    Last Post: 5th February 2007, 11:52 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •