Check status of printer using

Posted on 2008-06-24
Last Modified: 2013-11-07
I need to be able to determine if a printer exists and if it is online.  The name of the printer to be checked is stored as a setting of the program i am creating.   Is it possible to check that status of a printer using   The printer may be a local printer or network printer.
Question by:Mike_Stevens
  • 2
LVL 53

Accepted Solution

Dhaest earned 250 total points
ID: 21855124
Possible solution found at
Private Enum PrinterStatus

PrinterIdle = 3

PrinterPrinting = 4

PrinterWarmingUp = 5

' For more states see WMI docs.

End Enum

Private Function PrinterStatusToString(ByVal ps As PrinterStatus) As


Dim s As String

Select Case ps

Case PrinterStatus.PrinterIdle

s = "waiting (idle)"

Case PrinterStatus.PrinterPrinting

s = "printing"

Case PrinterStatus.PrinterWarmingUp

s = "warming up"

Case Else ' Vielleicht gibt es noch weitere Fälle...

s = "unknown state"

End Select

PrinterStatusToString = s

End Function

Private Sub Form1_Load( _

ByVal sender As System.Object, _

ByVal e As System.EventArgs _

) Handles MyBase.Load

Dim strPrintServer As String

strPrintServer = "localhost"

Dim WMIObject As String, PrinterSet As Object, Printer As Object

WMIObject = "winmgmts://" & strPrintServer

PrinterSet = GetObject(WMIObject).InstancesOf("win32_Printer")

For Each Printer In PrinterSet

MsgBox( _

Printer.Name & ": " & _

PrinterStatusToString(Printer.PrinterStatus) _


Next Printer

End Sub

Open in new window

LVL 53

Expert Comment

ID: 21855148
Another article about the subject
How to Check if your Printer is Connected
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") 



            ' 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.") 


                        ' printer is not offline 

                        Console.WriteLine("Your Plug-N-Play printer is connected.") 

                    End If 

                End If 


        End Sub 

    End Class 

Open in new window

LVL 27

Assisted Solution

planocz earned 250 total points
ID: 21855197
Here is another sample of how you can do it...

  Public Function InitializeDefaultPrinter() As String

        ' Set the specified printer to the default printer for this program. Return

        ' true if the printer was found.

        Dim objprinter As PageSettings = New PageSettings

        Dim strname As String = objprinter.PrinterSettings.PrinterName

        Return strname

    End Function

    Public Sub Printer_Check()

        Dim regKey As RegistryKey

        Dim sPrinterDriver As String

        Dim sPrinterPort As String

        Dim myProcess As New Process

        Dim sDefaultPrinter As String

        Dim keyValue As String

        'To get the Printer driver...

        sDefaultPrinter = InitializeDefaultPrinter()

        'If sDefaultPrinter.StartsWith("\") Then

        '    sDefaultPrinter = sDefaultPrinter.Substring(2)

        'End If

        keyValue = "Software\\Microsoft\\Windows NT\\CurrentVersion\\Print\\Printers\\" & sDefaultPrinter

        regKey = Registry.LocalMachine.OpenSubKey(keyValue, False)

        sPrinterDriver = regKey.GetValue("Printer Driver", 0)

        sPrinterPort = regKey.GetValue("Port", 0)


    End Sub

Open in new window


Expert Comment

ID: 23838921
Is there a way to see if there is a timeout error? For example, the printer runs out of paper and times out or throws an error..

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Calling web service and its methods dynamically 2 41
Runtime Error 2 28
Runtime Exceptions when trying to submit data 28 37
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now