Ryan Buddicom
Ryan Buddicom

Reputation: 1151

How to get the model number of any connected printer in vb .net

As the question states, I need to find the model number of a printer using vb dotNet.

Currently have been using the EnumPrinters API and checking the driver name, however certain printers are supported by the same named driver (ie the driver supports a series of printers) which does not allow me to differentiate between them.

I need the output to be <manufacturer> <model> <codes>.

Is this possible with vb.net/any other language

Upvotes: 4

Views: 2055

Answers (1)

Jason Hughes
Jason Hughes

Reputation: 778

Not going to code the whole thing for you but check out the DriverName property. Run the whole thing in debug mode to see other property's available to you. You'll need to add references to System.Drawing and System.Management.

Imports System.Drawing.Printing
Imports System.Management


Module Module1

    Sub Main()
        Dim printers = PrinterSettings.InstalledPrinters

        For Each printerName As String In printers
            Dim query As String = String.Format("SELECT * from Win32_Printer WHERE Name LIKE '%{0}'", printerName)
            Dim searcher As ManagementObjectSearcher = New ManagementObjectSearcher(query)
            Dim collection As ManagementObjectCollection = searcher.Get()

            For Each printer As ManagementObject In collection
                For Each propData As PropertyData In printer.Properties
                    Debug.WriteLine(String.Format("{0}: {1}", propData.Name, propData.Value))
                Next
            Next
        Next
    End Sub

End Module

Upvotes: 2

Related Questions