/build/static/layout/Breadcrumb_cap_w.png

VBScript Delete local Priners- Exclusions

Hi

I am creating a VBscript to delete local printers which is nice and easy. However I need to set up a list of exclusions. At the moment I have got the following which will delete all local printers except printer1.


strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer Where Network = FALSE and DeviceID <> 'Printer1'")
For Each objPrinter in colInstalledPrinters
objPrinter.Delete_
Next



How do I go about and add Printer2,Printer3 etc into the DeviceID <> part of the query.

Many thanks in advance

Jimmy

0 Comments   [ + ] Show comments

Answers (3)

Posted by: aogilmor 14 years ago
9th Degree Black Belt
0
don't reinvent the wheel, use %windir%\system32\prnmngr.vbs which comes with xp. there are other vbs files that are printer related as well.
Posted by: anonymous_9363 14 years ago
Red Belt
0
If the list isn't too lengthy, you could use basic SQL syntax, no? Something like:Select * from Win32_Printer Where (Network = FALSE) and (DeviceID <> 'Printer1' OR DeviceID <> 'Printer2' OR DeviceID <> 'Printer3')

If it is lengthy, or if the names come from some other function, I'd create a variable for the SQL string, build an array of exclusions, then loop through the array, adding names to the 'OR' statement, then execute it.
Posted by: elgwhoppo 14 years ago
Senior Purple Belt
0
Use inStr with the printer name in a vbscript. For example, this script sets permissions based on printer name and driver name:

On Error Resume Next
Set sho = Wscript.CreateObject("Wscript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

'********** Pull all non-networked printer information via WMI ***********
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer Where Network = FALSE")

'********** Do action IF 1) local printer 2) NOT the UPD printer 3) if driver contains "HP Universal Printing"
For Each objPrinter in colInstalledPrinters
If NOT InStr(objPrinter.Name, "HP Universal Printing") > 0 then
IF InStr(objPrinter.DriverName, "HP Universal Printing") > 0 then
'msgbox "subinacl.exe /printer """+objPrinter.Name+""" /grant=Users=F"
sho.run "subinacl.exe /printer """+objPrinter.Name+""" /grant=Users=F"
End if
End if
Next
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ