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

Remove/Add Printer connection using Script

Status
Not open for further replies.
Oct 23, 2003
108
GB
Hello,

I am using markdmac's script to remove all network attached printers and attach new network printers using GP logon script.

Below is the full and only script I am using......

Dim WSHNetwork

Set WSHNetwork = CreateObject("WScript.Network")

Set WSHPrinters = WSHNetwork.EnumPrinterConnections
For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 Step 2
If Left(WHSPrinters.Item(LOOP_COUNTER +1),2) = "\\" Then
WSHNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER+1),True,True
End If
Next

WSHNetwork.AddWIndowsPrinterConnection "\\TRB_SVR1\HP5000_1"

Set WSHNetwork = Nothing
Set WSHPrinters = Nothing

wscript.quit


But when I run it I recieve the error.

"Object Required WSHPrinters"

Any Advice?

Thanks
Fandab
 
Does the machine you are running this on have any network printers? Your collection may be coming up emtpy and you do not have the On error Resume Next that I have in my FAQ.

I hope you find this post helpful.

Regards,

Mark
 
Hi,

I got your script here, but dont find any reference to On Error resume next. Unless I have an older version.

Can you point me to it?

But, I have got 2 network printer connected to the computer.

Thanks
 
Thanks Mark,

Got it working now, but how can I make it so that it removes printers only attached to a certain server.

I noticed in your script that you use "anything with \\"
I tried to change it so that it reads

If Left(WSHPrinter.Item(LOOP_COUNTER +1),2 = "\\SERVERA" then

But it still removes all network printers.

I only need to remove printers attached to certain server.

Thanks
 
oops just realised that this is in the exchange 2003 forum.
Apologies if this confused anyone else.
 
Change the 2 in this line
If Left(WSHPrinter.Item(LOOP_COUNTER +1),2

make it the length of the \\ + server name

I hope you find this post helpful.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top