Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding a TCP/IP Printer via script

Status
Not open for further replies.

Popsea

MIS
Jun 24, 2002
29
US
Our company has a number of different locations, each with a number of printers. Normally we would just add these printers to a print server, however these locations don't have a print server. I would like to develop a script to do the following:

1. Remove all installed printers (except for locally attached printers).

2. Determine the IP of the computer.

3. Add all printers at that location based on the IP of the computer & copy the driver down to the computer if needed.

We want to setup it this way because a lot of our users travel from site to site and place a resource drain on the Service Desk to manually add printers when they are at these different locations. In addition, we want to keep the print spooling local and keep it off the WAN. Any direction or help you can provide would be appricated. All of our computers are either W2K or XP.
 
something like this might remove them for you:

Code:
Set objNetwork = CreateObject("WScript.Network")
Set colPrinters = objNetwork.EnumPrinterConnections

For i = 0 to colPrinters.Count - 1 Step 2
	If InStr(colPrinters.Item(i), "IP_") Then
		objNetwork.RemovePrinterConnection colPrinters.Item(i+1), True, True
	End If
Next

To determine the computers IP, there are several ways you can do it. One way could be

Code:
WScript.Echo IPAddr

Function IPAddr
'     On Error Resume Next

    Dim wmiQuery, objWMIService, objPing, objStatus, objNetwork
    
    Set objNetwork = CreateObject("WScript.Network")
    wmiQuery = "Select * From Win32_PingStatus Where " & _
    "Address = '" & objNetwork.ComputerName & "'"
    
    Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
    Set objPing = objWMIService.ExecQuery(wmiQuery)
    
    For Each objStatus in objPing
        IPAddr = objStatus.ProtocolAddress
    Next
End Function

As for the adding printer. Run this command at the cmd prompt see all the available options for installing/condfiguring a printer.

rundll32 printui.dll,PrintUIEntry /?

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
This is excellent advice. Thank you both. I will review your code and let you know if I have any questions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top