Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Deleting specific local printers via computer gpo script

Posted on 2007-08-01
9
Medium Priority
?
1,886 Views
Last Modified: 2012-09-19
Hi
I'm having trouble getting a local printer deleting script to work on WinXP machines. I can get the script to delete the computers local Printers when it boots but i want it to be more precise with what it actually deletes.
Our Prepress department have Creative Suite 2 which installs a local Adobe PDF printer. If I roll this script out as is it will delete this printer as well as the old ones we want to get rid of. I can not get it working as i keep getting an "unexpected next" error.
I want the script to be as generic as possible as there are loads of other departments with different print names so I would rather not have to specify each printer to delete.
Here is the code I have so far.

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_Printer Where Network = FALSE")

For Each objPrinter in colInstalledPrinters
If objPrinter.Name = "Adobe PDF" or "Microsoft Office Document Image Writer" then
next
else
objPrinter.Delete_
end if
Next

0
Comment
Question by:sabnews
8 Comments
 
LVL 32

Expert Comment

by:and235100
ID: 19611581
0
 
LVL 25

Expert Comment

by:Ron Malmstead
ID: 19612114
It's easier to do this in a batch file.  Instead of writing your own vbs, you should use the one that is built-in to windows.  See below.

cscript "%systemroot%\system32\prnmngr.vbs" -d -p "Microsoft Office Document Image Writer"
cscript "%systemroot%\system32\prnmngr.vbs" -d -p "Adobe PDF Writer"




0
 
LVL 1

Author Comment

by:sabnews
ID: 19615410
Xuserx2000 I need something that will delete all local printers apart from the two mentioned above. That code would only delete those two printers.

and235100 there doesn't seem to be a solution on that page. The last part about using the registry to delete the printers would mean i would have to have 20 or so different scripts to cover all the departments and offices. I would like something that will delete all local printers apart from the ones I specify.

I just need a way for the loop to skip the printers i specify in the IF statement.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:sabnews
ID: 19615720
I've got a little further. I have changed the code to an If not statement which now comes up with a type Mismatch error on the second printer in the IF NOT statement.

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_Printer Where Network = FALSE")

For Each objPrinter in colInstalledPrinters
If not objPrinter.Name = "Microsoft Office Document Image Writer" or "Adobe PDF" then
objPrinter.Delete_
end if
next

If I remove the "or" and the second printer name out of the IF NOT statement then it works fine and deletes all the printers apart from the one specified.
Does anybody know what I need to do to get the second part of the IF NOT statement working?
0
 
LVL 1

Author Comment

by:sabnews
ID: 19639527
Solved it now. Here is the script I'm putting into the startup gpo for the computers.

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_Printer Where Network = FALSE")

For Each objPrinter in colInstalledPrinters
If objPrinter.Name = "Microsoft Office Document Image Writer" or objPrinter.Name = "Adobe PDF" then
strdelete = false
else
objPrinter.Delete_
end if
next

Seems to work perfectly
0
 
LVL 32

Expert Comment

by:and235100
ID: 19640431
Glad that you got it worked out.

Ask a new, 0-point question here http://www.experts-exchange.com/Community_Support/General/ to request that this question be closed, and as you provided an answer yourself, you will be entitled to a points refund.
0
 
LVL 1

Accepted Solution

by:
Vee_Mod earned 0 total points
ID: 19678764
Closed, 250 points refunded.
Vee_Mod
Community Support Moderator
0
 

Expert Comment

by:BradLMComputers
ID: 38414029
Why don't you use a script to delete all the prtinters, then deploy the other ones via Group Policy
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

There are 2 things you must have in order to connect to the internet behind a router, The "Gateway IP" of the router, which is usually something like 192.168.xxx.1, I've seen routers with default values of: 192.168.0.1, 192.168.1.1, 192.168.11.1, …
Sometimes people don't understand why download speed shows differently for Windows than Linux.Specially, this article covers and shows the solution for throughput difference for Windows than a Linux machine. For this, I arranged a test scenario.I…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses

579 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