Forum Discussion

sastowe's avatar
sastowe
Super Contributor
12 years ago

determining if a local printer exists

I can find all sorts of reousrces for managing network printers online. I need to determine of a local printer exists by name. Does anyone know how to do this?

Thanks



S

2 Replies


  • Hello,

    You can use WMI to retrieve information on the connected printers. Then do a string compare or the like to determine if your printer is found.

    eg. To list printer details:





    Sub Printers() 

      strComputer = "."

      strQuery = "Select * From Win32_Printer" 





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

      Set colPrinters = objWMIService.ExecQuery(strQuery) 

          

      For Each objPrinter in colPrinters 

        strResult = objPrinter.Name 





        If objPrinter.Default Then 

          strResult = strResult & " - (Default)" 

        End If 





        If objPrinter.Local Then 

          strResult = strResult & " - Local Printer" 

        Else 

          strResult = strResult & " - Network Printer" 

        End If 





        Log.Message(strResult) 

      Next 

    End Sub 





    Cheers,

    Jackson