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

Comments

Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Answers

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.
Answered 07/24/2009 by: aogilmor
Ninth Degree Black Belt

Please log in to comment
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.
Answered 07/27/2009 by: VBScab
Red Belt

Please log in to comment
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
Answered 07/28/2009 by: elgwhoppo
Senior Purple Belt

Please log in to comment
Answer this question or Comment on this question for clarity