Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scan Network For Printers And Retrieve Printer Information

Status
Not open for further replies.

blounty

Technical User
Mar 23, 2006
46
Hi All,

I am really stumped. Is it possible to scan a network to pick up printers connected to it and then retrieve the printers information (name, ink levels, serial)? i hav been searching for a way to do this for a while now.

Any ideas would be greatly appreciated.

Regards

Alex
 
Sorry, Forgot to mention using vb.net vs 2005.

Thanks all.
 
I'm not sure how you would go about getting the serial number, but you can scan for the printers using WMI:

Code:
 Private Sub GetNetworkPrinters()
        Dim printers As Management.ManagementObjectCollection = Nothing
        Dim searcher As Management.ManagementObjectSearcher = Nothing
        Dim printer As Management.ManagementObject = Nothing
        searcher = New Management.ManagementObjectSearcher("Select * from Win32_Printer")
        printers = searcher.Get
        Dim strPrinters As String = Nothing
        Dim name As String = Nothing
        Dim errorState As Integer = Nothing
        Dim ink As String = Nothing
        For Each printer In printers
            errorState = printer.Properties("DetectedErrorState").Value
            If errorState = 5 Then
                ink = "low"
            ElseIf errorState = 6 Then
                ink = "No Ink"
            Else
                ink = "Acceptable Ink Level"
            End If
            name = printer.Properties("Name").Value
            strPrinters &= "name: " & name & " ink: " & ink & vbCrLf
        Next

    End Sub

For a complete list of available properties check out:


Also, if you want to quickly list attached printers, you can do something like this:

Code:
  Dim objPrint As New System.Drawing.Printing.PrinterSettings()
        Dim strItem As String
        Dim strPrinters As String
        For Each strItem In objPrint.InstalledPrinters
            strPrinters &= strItem & vbCrLf

        Next

Hope this helps.

Regards,

-Kevin
 
Hi Kevin,

Thanks for that! that worked great and picked up the network i have setup up on my computer. is there a way of getting all printers on the network? by searching in a range of ip's or along those lines?

Thank you so much for your help.

Alex
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top