troubleshooting Question

Check how many printers are mapped and combine it with an if condition

Avatar of Silvan
Silvan asked on
VB ScriptPrinters and Scanners
3 Comments1 Solution63 ViewsLast Modified:
Dear community,
Actually we plan to optimize our VBS logon script (unfortunately my VBS skills are not the best).
There is a row, in which we start an external application to set the customer's default printer (setdefaultprinter.exe). It is a simple program, which lets the user choose his favourite printer.
Some users do not have a printer or only one. The program "setdefaultprinter.exe" should only start if the users has two or more printer mapped.

Something like that:
If "2 or more printers are available" run setdefaultprinter.exe
else do nothing.

Based on some internet research I found the following script:

Function printerExists(str)
    printerExists = False
    Dim objWMIService
    Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
    Dim colPrinters
    Set colPrinters = objWMIService.ExecQuery("Select * From Win32_Printer")
    Dim objPrinter
    For Each objPrinter In colPrinters
        If objPrinter.Name = str Then
            printerExists = True
            Exit For
        End If
End Function

But how can I combine it with my "IF condition"?

Thanks for any help

Best regards,
Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros