Logon script to remove all network printer and install new printer

Posted on 2009-02-19
Medium Priority
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
  • 3
LVL 23

Expert Comment

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

Accepted Solution

gecko_au2003 earned 1500 total points
ID: 23689680
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

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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
This article explains the fundamentals of industrial networking which ultimately is the backbone network which is providing communications for process devices like robots and other not so interesting stuff.
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…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

569 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