473,326 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Detecting if a printer is connected to the PC

I have an application that prints bar code labels for each new record
added to the system. It uses a particular printer to do this (Brother
P-Touch QL500). What I'd like to do is not send the request to print
the label if the printer isn't physically connected to the PC. Is there
a way that I can detect this?

Aug 18 '06 #1
3 4730
http://www.codeproject.com/csharp/printeroffline.asp

Sorry the code is in c#

"BobRoyAce" <br**@omegasoftwareinc.comwrote in message
news:11**********************@74g2000cwt.googlegro ups.com...
I have an application that prints bar code labels for each new record
added to the system. It uses a particular printer to do this (Brother
P-Touch QL500). What I'd like to do is not send the request to print
the label if the printer isn't physically connected to the PC. Is there
a way that I can detect this?

Aug 18 '06 #2
Thanks for the pointer. I am having a little trouble converting this
code to VB in my app. The biggest problem that I am having is dealing
with the line

using System.Management;

I tried adding a line at the beginning of my module

Imports System.Management

but System.Management is not recognized. What do I do?

Lastly, I am unsure what the @ symbol in the following line is for:
ManagementScope scope = new ManagementScope(@"\root\cimv2");

I translated it to:
Dim scope As ManagementScope = New ManagementScope("\root\cimv2")

completing removing the @ symbol. Is this correct?

When I've got this all figured out, I'll post my working VB code.

Aug 18 '06 #3
Never mind...I figured out that I just need to add a reference to my
project to System.Management!

Final VB code follows:

Public Function PrinterIsOnline(ByVal sPrinterName As String) As
Boolean
'// Set management scope
Dim scope As ManagementScope = New ManagementScope("\root\cimv2")
scope.Connect()

'// Select Printers from WMI Object Collections
Dim searcher As ManagementObjectSearcher = New
ManagementObjectSearcher("SELECT * FROM Win32_Printer")

Dim printerName As String = String.Empty
For Each printer As ManagementObject In searcher.Get()
printerName = printer("Name").ToString().ToLower()
Debug.Print(printerName)
If (printerName.Equals(sPrinterName)) Then
If (printer("WorkOffline").ToString().ToLower().Equal s("true"))
Then
' Printer is offline by user
Return False
Else
' Printer is not offline
Return True
End If
End If
Next
End Function ' PrinterIsOnline

Aug 18 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Sam-Kiwi | last post by:
I've spent the last 6 months developing a pay-per-download website using ASP.NET Users purchase documents and then download them. The intention is that users are only charged for documents...
2
by: Tor Inge Schulstad | last post by:
Hi I'm developing a POS software using an Epson TM-T88iii printer with a cash drawer connected to the printer. The printer is connected via a usb interface to the pc. Can anyone tell me how I...
0
by: What What | last post by:
I'm trying to print a report to a printer directly using PHP printer function. I have code like the following one. <? if($handle=printer_open()){ print "Printer Connected<br>"; }...
0
by: jay | last post by:
Dear friends, I have a new task to do that I know nothing about. I am to design a printer driver (I think). The requirements of the project are: 1. design a printer driver - the printer...
0
by: neeraj | last post by:
Hi all I have developed on desktop application in Visual Basic for Hotel Management and my client requires multiple printing options here I have multiple printers first default printer which...
2
by: =?iso-8859-1?Q?Vicente_Garc=EDa?= | last post by:
Hello all, I have an a bit strange printer and I would like to connect a C# program running on my computer to the printer. I know that the printer can be connected by LAN (TCP/IP protocol,...
9
by: id10t error | last post by:
Hello, I am going to be using a Symbol WT4090 to scan items. I need to printer a tag from the Zebra ql320 plus. I am trying to do this is Visual basic 2005. Does anyone know and good site to...
4
by: Stefano | last post by:
I've got a problem using printer functions with my network printer shared on another PC as \\192.168.1.3\HP If the printer is connected and reachable, printer_***() functions work correctly. ...
3
by: ypytt | last post by:
Hi all, I'm developing a Windows application in C#. It generates reports using ReportViewer. These reports should be printed on a dot matrix printer. However, there is a problem. The application...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.