Check Printer Status with vb.net

Good Morning. Nothing exciting last night. I am ok with that. I’ve had WAY too much excitement as of late.

What we need to do is check if the printer is offline or online prior to printing.

Make it a great day!

Imports System
Imports System.Management
    Class PrinterOffline
        <STAThread()> _
        Private Shared Sub Main(ByVal args As String())
            ‘ Set management scope
            Dim scope As New ManagementScope("\root\cimv2")
            scope.Connect()
            ‘ Select Printers from WMI Object Collections
            Dim searcher As New ManagementObjectSearcher("SELECT * FROM Win32_Printer")
            Dim printerName As String = ""
            For Each printer As ManagementObject In searcher.[Get]()
                printerName = printer("Name").ToString().ToLower()
                If printerName.Equals("hp deskjet 930c") Then
                    Console.WriteLine("Printer = " + printer("Name"))
                    If printer("WorkOffline").ToString().ToLower().Equals("true") Then
                        ‘ printer is offline by user
                        Console.WriteLine("Your Plug-N-Play printer is not connected.")
                    Else
                        ‘ printer is not offline
                        Console.WriteLine("Your Plug-N-Play printer is connected.")
                    End If
                End If
            Next
        End Sub
    End Class

 

Advertisements
  1. #1 by Thanks on September 25, 2012 - 11:06 am

    Exactly what I was looking for. Thank you.

  2. #2 by Marc Gurt on January 29, 2015 - 1:47 am

    It work’s! Thanks for the job 😉

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: