Logon script to remove all network printer and install new printer

Posted on 2009-02-19
Last Modified: 2013-11-30
What is the logon script to remove all the network printers and to remap new printers. I have windows 2003 server with 2 network printers installed and shared for 100 windows XP clients. I need to change the server.
Question by:ganisha_amrb
    LVL 23

    Expert Comment

    Just as an FYI - am putting one together and will post back as soon as I get a working example.
    LVL 23

    Accepted Solution

    here is an example script that I did quite some time ago

    If you need help with it or want to understand it a bit more then post back but basically I have delcared room names at the start that are

    IT2 etc

    and each of those room names has the share name assigned to it so if you have a hp printer that is in room 1 then I have assigned the share name to the room name variable

    also you will need to change the server name in the add printer function when you call it so that it points to your server via its netbios name or ip address ie

    currently it is

        Case "ES"
          call AddPrinter("\\cse2k01\",EdSupport)

    where as you will need to alter it so that it is

        Case "ES"
          call AddPrinter("\\your_server\", variable)

    anyway HTH

    Post back if the computer name part does not work for you and let me know what your client computer names are like and we can edit the code below.

    Dim SleepTime
    'upper school printers
    Dim IT1
    Dim IT2
    Dim IT3
    Dim IT4
    Dim IT6
    Dim TechU
    Dim LibrarySixth
    'lower school printers
    Dim ICT5
    Dim ICT6
    Dim ICT8
    Dim TechL
    Dim EdSupport
    Dim AName
    IT1 = "kyoceraM"
    Set WSHNetwork = CreateObject("WScript.Network")
    strComputer = WSHNetwork.ComputerName
    AName = Left(strComputer,Len(strComputer)-4)
    Select Case AName
        Case "IT1"
    	call AddPrinter("\\cse2k01\",IT1)
    	MsgBox "Added Printer : " & IT1
        Case "IT2"
    	call AddPrinter("\\cse2k01\",IT2)
    	MsgBox "Added Printer : " & IT2
        Case "IT3"
    	call AddPrinter("\\cse2k01\",IT3)
    	MsgBox "Added Printer : " & IT3
        Case "IT4"
    	call AddPrinter("\\cse2k01\",IT4)
    	MsgBox "Added Printer : " & IT4
        Case "DT"
    	call AddPrinter("\\cse2k01\",TechU)
    	MsgBox "Added Printer : " & TechU
        Case "IT6"
    	call AddPrinter("\\cse2k01\",IT6)
    	MsgBox "Added Printer : " & IT6
        Case "LibrarySixth"
    	call AddPrinter("\\cse2k01\",LibrarySixth)
    	MsgBox "Added Printer : " & LibrarySixth
        Case "ICT5"
    	call AddPrinter("\\cse2k01\",ICT5)
    	MsgBox "Added Printer : " & ICT5
        Case "ICT6"
    	call AddPrinter("\\cse2k01\",ICT6)
    	MsgBox "Added Printer : " & ICT6
        Case "ICT8"
    	call AddPrinter("\\cse2k01\",ICT8)
    	MsgBox "Added Printer : " & ICT8
        Case "DTLS"
    	call AddPrinter("\\cse2k01\",TechL)
    	MsgBox "Added Printer : " & TechL
        Case "ES"
    	call AddPrinter("\\cse2k01\",EdSupport)
    	MsgBox "Added Printer : " & EdSupport
    End Select
    Public Function AddPrinter(ByRef Server,ByRef strPrinter)
    Set WshNetwork = CreateObject("WScript.Network")
    rem ** This will delete existing printers **
    On Error Resume Next
    Set oPrinters = WshNetwork.EnumPrinterConnections
            For i = 1 to oPrinters.Count - 1 Step 2
                   WshNetwork.RemovePrinterConnection oPrinters.Item(i)
    rem ** Setup new printer connection **
    WshNetwork.AddWindowsPrinterConnection Server & strPrinter
    rem ** Pause Script **
    WScript.Sleep SleepTime*1000
    rem ** Setup default printer **
    WshNetwork.SetDefaultPrinter Server & strPrinter
    End Function

    Open in new window

    LVL 23

    Expert Comment

    why the B grade - fully working script that sets it as default , removes all printers etc as requested ?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Learn about cloud computing and its benefits for small business owners.
    Don’t let your business fall victim to the coming apocalypse – use our Survival Guide for the Fax Apocalypse to identify the risks and signs of zombie fax activities at your business.
    Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…
    After creating this article (, I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now