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

VB Script to "Remove All Network printers connected to \\s" 1

Status
Not open for further replies.

mrshabbs

IS-IT--Management
Mar 29, 2011
1
0
0
GB
Any vb wizards out there that can help with this please? I wish to create a vb script that removes all network printers on a client xp workstation that are connected to a print server named "\\STSV1000". The script below (which I have not written) deletes all networked printers connected to any print server. I do not understand how to edit the script so that only printers connected to "\\STSV1000" are removed. Any helpers please?



'Declare and set a Network Object
Dim WSHNetwork
Set WSHNetwork = CreateObject("WScript.Network")

'Declare and and get all printer connections
Dim WSHPrinters
Set WSHPrinters = WshNetwork.EnumPrinterConnections

'Resume when an error occurs
On Error Resume next

Dim prcount 'Printer Count
Dim prName 'Printer Name

'Loop through the printers
For prcount = 0 To WSHPrinters.Count - 1 Step 2
'Get the printer name
prName = WSHPrinters.Item(prcount + 1)

'If the printer name starts with a \\ the remove it
If Left(prName, 2) = "\\" Then
WshNetwork.RemovePrinterConnection prName, True, True
End If


Next

On Error Goto 0
 

Try this:

For prcount = 0 To WSHPrinters.Count - 1 Step 2
'Get the printer name
prName = WSHPrinters.Item(prcount + 1)

If InStr(prName, "\\STSV1000") > 0 Then 'printer name has "\\STSV1000" in it
WshNetwork.RemovePrinterConnection prName, True, True
End If

Next

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top