Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Printer Removal Script

Posted on 2007-12-05
13
Medium Priority
?
785 Views
Last Modified: 2013-12-04
I need to remove all network printers from everyone's machine. I know you can script a script to add network printers. Is there a way that you can write a script on log off to remove all network printers?
0
Comment
Question by:Headmasters
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
  • +2
13 Comments
 
LVL 27

Expert Comment

by:michko
ID: 20412864
This script includes a section to disconnect network printers:
http://www.tek-tips.com/faqs.cfm?fid=5798
0
 
LVL 1

Author Comment

by:Headmasters
ID: 20418341
Im using as suggested

ON ERROR RESUME NEXT
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
wscript.quit

However i keep getting a Scrip Error saying Expected statement. Code 800A0400, Source Compilation error
0
 
LVL 27

Expert Comment

by:michko
ID: 20419365
hmuser - sorry, don't know what is causing that error.  I've posted another questions asking for review of this script here:  http://www.experts-exchange.com/Hardware/Peripherals/Printers_Scanners/Q_23005909.html

We'll pick up another expert who can straighten it out for you.
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.

 
LVL 12

Expert Comment

by:Kurt_Braeckmans
ID: 20419510
I think that the step 2 gives the error (but I'm not sure)
So can you try this:




ON ERROR RESUME NEXT
Set WSHPrinters = WSHNetwork.EnumPrinterConnections
For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 
If Left(WSHPrinters.Item(LOOP_COUNTER +1),2) = "\\" Then
WSHNetwork.RemovePrinterConnection WSHPrinters.Item
(LOOP_COUNTER +1),True,True
End If
wscript.quit

Open in new window

0
 
LVL 1

Author Comment

by:Headmasters
ID: 20419676
I have tried that but it comes back with expected statement.

Line 6
Char 1
Error Expected Statement
Code 800A0400
Source Compilation error
0
 
LVL 12

Expert Comment

by:Kurt_Braeckmans
ID: 20419740
Do you have the variable WSHNetwork declared?
See line 2 how to declare it?

ON ERROR RESUME NEXT
Set WSHNetwork = CreateObject("WScript.Network")
Set WSHPrinters = WSHNetwork.EnumPrinterConnections
For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 
If Left(WSHPrinters.Item(LOOP_COUNTER +1),2) = "\\" Then
WSHNetwork.RemovePrinterConnection WSHPrinters.Item
(LOOP_COUNTER +1),True,True
End If
wscript.quit

Open in new window

0
 
LVL 12

Expert Comment

by:Kurt_Braeckmans
ID: 20419762
and also forgot (must learn to read everything.....)
add Next in the script.
ON ERROR RESUME NEXT
Set WSHNetwork = CreateObject("WScript.Network")
Set WSHPrinters = WSHNetwork.EnumPrinterConnections
For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 
 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
 
LVL 1

Author Comment

by:Headmasters
ID: 20419791
Im new to the scripting world sorry

Error now is Line 7
Char 3
Expected statement
800A0400
Compilation
0
 
LVL 12

Expert Comment

by:Kurt_Braeckmans
ID: 20419809
it's nothing...
try this:
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
 
LVL 7

Expert Comment

by:avatar-e
ID: 20419867
If the error is in the line 7, you need to delete some breaklines:

  WSHNetwork.RemovePrinterConnection WSHPrinters.Item
  (LOOP_COUNTER +1),True,True

Comes to be:
  WSHNetwork.RemovePrinterConnection WSHPrinters.Item, (LOOP_COUNTER +1),True,True
0
 
LVL 1

Author Comment

by:Headmasters
ID: 20419958
It now runs with no errors but the network printers arent removed from the printers and faxes.
0
 
LVL 7

Accepted Solution

by:
avatar-e earned 400 total points
ID: 20420114
And now?
on error resume next
Dim WshNetwork, WSHPrinters
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set WSHPrinters = WshNetwork.EnumPrinterConnections
For Each Printer In WSHPrinters
If Left(printer,2) = "\\" Then
	 WshNetwork.RemovePrinterConnection printer,True,True
End If
Next

Open in new window

0
 

Expert Comment

by:venema
ID: 20909227
All solutions above did not work for me.
The only solution which worked was:

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
      ("Select * From Win32_Printer Where Network = True")
For Each objPrinter in colInstalledPrinters
      objPrinter.Delete_
Next
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a guide to the following problem (not exclusive but here) on Windows: Users need our support and we supporters often use global administrative accounts to do this. Using these accounts safely is a real challenge. Any admin who takes se…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question