Link to home
Start Free TrialLog in
Avatar of Mike_Stevens
Mike_StevensFlag for United States of America

asked on

Check status of printer using vb.net

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 vb.net?   The printer may be a local printer or network printer.
ASKER CERTIFIED SOLUTION
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Another article about the subject
How to Check if your Printer is Connected
http://www.codeproject.com/KB/printing/printeroffline.aspx
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 

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ghendric
ghendric

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..