We help IT Professionals succeed at work.
Get Started

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

Silvan asked
Last Modified: 2016-01-15
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,
Watch Question
Top Expert 2016
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE