[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 294
  • Last Modified:

Need someone to review a script (to delete all network printers) error - pointer to another question

I am not a script guru, I can get by for my purposes, but don't know scripts inside and out.  I posted an answer to the below question:
http://www.experts-exchange.com/Hardware/Peripherals/Printers_Scanners/Q_23003197.html?cid=238#a20418341

The poster is getting an error when running the script.  I don't know what is causing it, so am looking for someone who can review it the question and give the poster some more suggestions.

Thanks,

michko
0
michko
Asked:
michko
  • 3
  • 2
2 Solutions
 
Kurt_BraeckmansCommented:
I think that this can help you
ON ERROR RESUME NEXT
Set WSHNetwork = CreateObject("WScript.Network")
Set WSHPrinters = WSHNetwork.EnumPrinterConnections
For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 step 2
 If Left(WSHPrinters.Item(LOOP_COUNTER +1),2) = "\\" Then
  WSHNetwork.RemovePrinterConnection WSHPrinters.Item
  (LOOP_COUNTER +1),True,True
 End If
next
wscript.quit

Open in new window

0
 
Kurt_BraeckmansCommented:
michko,

I've made an error in the script.
attempt 2:
ON ERROR RESUME NEXT
Set WSHNetwork = CreateObject("WScript.Network")
Set WSHPrinters = WSHNetwork.EnumPrinterConnections
For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 step 2
 If Left(WSHPrinters.Item(LOOP_COUNTER +1),2) = "\\" Then
  WSHNetwork.RemovePrinterConnection 
  WSHPrinters.Item(LOOP_COUNTER +1),True,True
 End If
next
wscript.quit

Open in new window

0
 
michkoAuthor Commented:
Thanks.  Once solved for poster, I'll credit points here also.  Poster only put 50 pts for their question, so it won't violate the 500 max limit.  Appreciate the help.
0
Threat Trends for MSPs to Watch

See the findings.
Despite its humble beginnings, phishing has come a long way since those first crudely constructed emails. Today, phishing sites can appear and disappear in the length of a coffee break, and it takes more than a little know-how to keep your clients secure.

 
avatar-eCommented:
You tried my last code?
0
 
Kurt_BraeckmansCommented:
credit goes to avatar-e.

Kurt
0
 
michkoAuthor Commented:
My thanks to both of you for your help.  
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now