+ Post New Thread
Results 1 to 12 of 12
Windows Server 2000/2003 Thread, Removing Network Printer in Technical; Morning, I currently have a VB script that maps all the printers when people logon. Now i'm having a problem ...
  1. #1

    Little-Miss's Avatar
    Join Date
    Oct 2007
    Location
    London
    Posts
    5,508
    Thank Post
    2,371
    Thanked 741 Times in 454 Posts
    Blog Entries
    2
    Rep Power
    541

    Removing Network Printer

    Morning,

    I currently have a VB script that maps all the printers when people logon.

    Now i'm having a problem with my staff one. After a bit of fiddling I have managed to get a long neglected printer working in the staff room, but unfortunately it is appearing twice on their printer list. The working one is Staff-Room but its also bringing up Staff Room which throws up an error message.

    The script is in this format...

    Code:
    if left(compname,4) = "INFS" then 
    
    	PrinterPath = "\\curricsvr1\JUNIOR-SUITE"
    	PrinterPath2 = "\\curricsvr1\INFANT-SUITE"
    	PrinterPath3 = "\\curricsvr1\FOUNDATION"
    	PrinterPath4 = "\\curricsvr1\INFANT-LIBRARY"
    	PrinterPath5 = "\\curricsvr1\STAFF-ROOM"
    	
      	WshNetwork.AddwindowsPrinterConnection PrinterPath
      	WshNetwork.AddwindowsPrinterConnection PrinterPath2
    	WshNetwork.AddwindowsPrinterConnection PrinterPath3
    	WshNetwork.AddwindowsPrinterConnection PrinterPath4
    	WshNetwork.AddwindowsPrinterConnection PrinterPath5
    	WshNetwork.SetDefaultPrinter "\\curricsvr1\INFANT-SUITE"
    
    end if

  2. #2

    Join Date
    Jun 2010
    Posts
    10
    Thank Post
    9
    Thanked 5 Times in 4 Posts
    Rep Power
    0
    I delete all printers first, then add them:

    Code:
    Set WshNetwork = CreateObject("WScript.Network")
    On Error Resume Next
    Set oPrinters = WshNetwork.EnumPrinterConnections
            For i = 1 to oPrinters.Count - 1 Step 2
                  WshNetwork.RemovePrinterConnection oPrinters.Item(i)
            Next
    
    Set WshNetwork = CreateObject("WScript.Network")
    WshNetwork.AddWindowsPrinterConnection "\\Server01\printer01"
    WshNetwork.AddWindowsPrinterConnection "\\Server01\printer02"
    WshNetwork.AddWindowsPrinterConnection "\\Server01\printer03"
    rem ** Setup default printer **
    WshNetwork.SetDefaultPrinter "\\Server01\Printer02"

  3. 2 Thanks to ted_baker:

    Little-Miss (28th June 2010), stevenlong1985 (2nd November 2010)

  4. #3

    3s-gtech's Avatar
    Join Date
    Mar 2009
    Location
    Wales
    Posts
    2,698
    Thank Post
    143
    Thanked 542 Times in 486 Posts
    Rep Power
    148
    Same here, our script deletes all printers first, then re-adds them. This ironed out a few quirks.

  5. Thanks to 3s-gtech from:

    Little-Miss (28th June 2010)

  6. #4

    Little-Miss's Avatar
    Join Date
    Oct 2007
    Location
    London
    Posts
    5,508
    Thank Post
    2,371
    Thanked 741 Times in 454 Posts
    Blog Entries
    2
    Rep Power
    541
    so, if i add...

    Code:
    on error resume next
    
    Set WshNetwork = CreateObject("WScript.Network")
    
    Dim Compname
    
    Compname = WSHNetwork.ComputerName
    
    Set oPrinters = WshNetwork.EnumPrinterConnections
            For i = 1 to oPrinters.Count - 1 Step 2
                  WshNetwork.RemovePrinterConnection oPrinters.Item(i)
    
            Next
    
    if left(compname,4) = "INFS" then 
    
    	PrinterPath = "\\curricsvr1\JUNIOR-SUITE"
    	PrinterPath2 = "\\curricsvr1\INFANT-SUITE"
    	PrinterPath3 = "\\curricsvr1\FOUNDATION"
    	PrinterPath4 = "\\curricsvr1\INFANT-LIBRARY"
    	PrinterPath5 = "\\curricsvr1\STAFF-ROOM"
    	
      	WshNetwork.AddwindowsPrinterConnection PrinterPath
      	WshNetwork.AddwindowsPrinterConnection PrinterPath2
    	WshNetwork.AddwindowsPrinterConnection PrinterPath3
    	WshNetwork.AddwindowsPrinterConnection PrinterPath4
    	WshNetwork.AddwindowsPrinterConnection PrinterPath5
    	WshNetwork.SetDefaultPrinter "\\curricsvr1\INFANT-SUITE"
    
    end if
    to my script like this it should work?

  7. #5

    Join Date
    Jun 2010
    Posts
    10
    Thank Post
    9
    Thanked 5 Times in 4 Posts
    Rep Power
    0
    Try it, but on a test PC first.

  8. #6
    DEvans's Avatar
    Join Date
    Sep 2010
    Location
    Droitwich, Worcestershire
    Posts
    72
    Thank Post
    3
    Thanked 16 Times in 10 Posts
    Rep Power
    21
    Downfall of course of removing all printers is that you will lose any local printers you might have installed on local machines as well as delaying your login.

    If you're running a large network with many networked printers you might find it takes a while to remap them all. In your instance, its probably best to remove that troublesome printer and leave the other printers be. Saves you time and solves the issue. Unless of course you only have like < 8 printers or something, then it shouldn't make too much of a big deal, but watch your local printers. (if any)

  9. #7
    wesleyw's Avatar
    Join Date
    Dec 2005
    Location
    Kingswinford
    Posts
    2,205
    Thank Post
    223
    Thanked 50 Times in 44 Posts
    Blog Entries
    1
    Rep Power
    30
    I'm not sure but I don't believe that script would delete locally installed printers.

    Wes

  10. #8

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,680
    Thank Post
    3,210
    Thanked 1,030 Times in 955 Posts
    Rep Power
    361
    Quote Originally Posted by wesleyw View Post
    I'm not sure but I don't believe that script would delete locally installed printers.

    Wes
    Am sure RIC's post is still on edugeek somewhere ref the printer script he did - you could take the bit of coding at the start ref the If statement to check if it is an LPR or USB connection and if so to ignore it otherwise to remove the printer connections as per the chunk of code you added at the start of your snippet and leave the rest of your code as is

  11. #9
    chazzy2501's Avatar
    Join Date
    Jan 2008
    Location
    South West
    Posts
    1,774
    Thank Post
    213
    Thanked 263 Times in 213 Posts
    Rep Power
    67
    You could avoid scripting altogether and use client side extensions, if not to map the printers then there is atleast the option to remove all networked printers. Really it's so easy to deploy printers with CSE, as long as it's not on vista.

  12. #10
    DEvans's Avatar
    Join Date
    Sep 2010
    Location
    Droitwich, Worcestershire
    Posts
    72
    Thank Post
    3
    Thanked 16 Times in 10 Posts
    Rep Power
    21
    Quote Originally Posted by mac_shinobi View Post
    You could take the bit of coding at the start ref the If statement to check if it is an LPR or USB connection and if so to ignore it otherwise to remove the printer connections
    Or alternatively you could simply perform an IF Statement to see if the printer's name begins with "\\" . Not sure how complex it is to check for USB or LPR, but I introduced a code in my login script to just check the name. Similar to the below.

    Code:
    'Remove all Network printers but not local printers
    Set Printers = WshNetwork.EnumPrinterConnections
    
    If ObjFSO.FileExists(strDirectory & strFile) = false Then
    	For i = 0 to Printers.Count - 1 Step 2
    
        	If Left(ucase(Printers.Item(i+1)),2) = "\\" Then
            WSHNetwork.RemovePrinterConnection Printers.Item(i+1)
        	End IF
    	Next
    Obviously you would need to change to match your defined objects.

    Thats what I use anyway. In some cases a login script might not remove local printers, it depends on the script and what commands you have used, I think anyway.

  13. #11
    box_l's Avatar
    Join Date
    May 2007
    Location
    Herefordshire
    Posts
    424
    Thank Post
    67
    Thanked 89 Times in 74 Posts
    Rep Power
    61
    this removes printers but leaves ltp and usb ones alone
    Code:
    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
    BoX
    Last edited by box_l; 6th October 2010 at 11:50 AM.

  14. #12


    Join Date
    Jan 2009
    Posts
    1,218
    Thank Post
    147
    Thanked 238 Times in 164 Posts
    Rep Power
    155
    We use rundll32 commands in a login script to delete all installed printers, then to install the printer specific to that room.

    E.G.

    rundll32 printui.dll,PrintUIEntry /dn /q /n\\servername\printersharename - deletes a printer

    rundll32 printui.dll,PrintUIEntry /in /q /n\\servername\printersharename - installs printer


    Works for us, script runs at log-on, takes about 10 seconds......means a different batch file for every room, but once they're done, they're done.

    And I don't know about anyone else, but it looks like being a long time before we install or refurbish any new or existing rooms. Or even buy any new printers.

SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 5
    Last Post: 30th May 2010, 08:10 PM
  2. Replies: 0
    Last Post: 30th May 2010, 08:04 PM
  3. Network Printer
    By HiredGoon in forum Wireless Networks
    Replies: 3
    Last Post: 5th June 2008, 02:35 PM
  4. Network PDF Printer
    By ICTNUT in forum Windows
    Replies: 22
    Last Post: 14th March 2008, 02:57 PM
  5. Best A3 colour network printer
    By Paid_Peanuts in forum Hardware
    Replies: 5
    Last Post: 26th February 2008, 09:55 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
  •