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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check for, add, and remove printers 1

Status
Not open for further replies.

efiftythree

IS-IT--Management
Jan 13, 2006
27
0
0
US
Hello all!

Here is what I want to do. At login I want to check to see if printer \\bhc2\cd_3800dtn is installed. If that printer is installed I want to end the script. If that printer is not installed I want to remove a couple of existing printers and install a new printer. The existing printers I want to remove are installed as local printer via a tcp/ip port which connects to a jetdirect not a print server so I don’t know if I can use a UNC path or not. Any help would be greatly appreciated.

Here is the code that I have attempted to create after browsing several threads in this forum. It errors out at the "Else" because I have not implemented that correctly as I don't really know how.

Code:
Set WSHPrinters = WSHNetwork.EnumPrinterConnections
PrinterPath = "\\bhc2\cd_2800dtn"

For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 Step 2
    If WSHPrinters.Item(LOOP_COUNTER +1) = PrinterPath Then
    End If
Else
	objNetwork.RemovePrinterConnection "LaserJet 5Si"
	objNetwork.RemovePrinterConnection "Color LaserJet 4550"
	On Error Resume Next
	Set net = CreateObject("WScript.Network")
	net.AddWindowsPrinterConnection "\\bhc2\CD_3800dtn"
End If
 
GIve this a try
Code:
On Error Resume Next
Set objNetwork = CreateObject("WScript.Network")
Set WSHPrinters = WSHNetwork.EnumPrinterConnections
PrinterPath = "\\bhc2\cd_2800dtn"

For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 Step 2
    If WSHPrinters.Item(LOOP_COUNTER +1) = PrinterPath Then
    	WScript.Quit
    End If
Next

objNetwork.RemovePrinterConnection "LaserJet 5Si"
objNetwork.RemovePrinterConnection "Color LaserJet 4550"
objNetwork.AddWindowsPrinterConnection "\\bhc2\CD_3800dtn"

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top