Finding a printer; need help

Finding a printer; need help

am 07.05.2008 16:35:22 von Deane.Rothenmaier

This is a multipart message in MIME format.
--===============0749953207==
Content-Type: multipart/alternative;
boundary="=_alternative 005025C986257442_="

This is a multipart message in MIME format.
--=_alternative 005025C986257442_=
Content-Type: text/plain; charset="US-ASCII"

Gurus,

Anybody know of a Perl module that can tell me 1. If there's a printer
physically connected to a parallel (or serial) port on a PC and, 2. what
printer it is? I've got a project that wants this info, and I've pretty
much gotten nowhere trying to use WMI (unless I've missed something). In
one instance, it (WMI) identifies seven printers connected to LPT1:, and
says that all of them are in "Idle" status. Anybody want to assess the
accuracy of that result? I know, it's just reading the registry (I
think); so the information I need must be elsewhere.

True confession time: I'm at a loss here, and in need of your guidance.

Thanks!!!!!!!

Deane Rothenmaier
Programmer/Analyst
Walgreens Corp.
847-914-5150

There is something fascinating about science. One gets such wholesale
returns of conjecture out of such a trifling investment of fact. -- Mark
Twain
--=_alternative 005025C986257442_=
Content-Type: text/html; charset="US-ASCII"



Gurus,



Anybody know of a Perl module that can
tell me 1. If there's a printer physically connected to a parallel (or
serial) port on a PC and, 2. what printer it is? I've got a project that
wants this info, and I've pretty much gotten nowhere trying to use WMI
(unless I've missed something). In one instance, it (WMI) identifies seven
printers connected to LPT1:, and says that all of them are in "Idle"
status. Anybody want to assess the accuracy of that result?  I know,
it's just reading the registry (I think); so the information I need must
be elsewhere.




True confession time: I'm at a loss
here, and in need of your guidance.




Thanks!!!!!!!



Deane Rothenmaier

Programmer/Analyst

Walgreens Corp.

847-914-5150



There is something fascinating about science. One gets such wholesale returns
of conjecture out of such a trifling investment of fact. -- Mark Twain

--=_alternative 005025C986257442_=--


--===============0749953207==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============0749953207==--

RE: Finding a printer; need help

am 07.05.2008 17:30:34 von Scott_Campbell

Deane, try these lines of Perl for WMI:

use Win32::OLE qw(in with);

$WMI =3D Win32::OLE->new('WbemScripting.SWbemLocator');
$Services =3D $WMI->ConnectServer("", "root/cimv2");
my $Printer_set =3D $Services->InstancesOf("Win32_Printer");
=

foreach my $object (Win32::OLE::Enum->All($Printer_set)) {
print "Caption: $object->{'Caption'}\n";
print "Device ID: $object->{'DeviceID'}\n";
print "Local: $object->{'Local'}\n";
print "Network: $object->{'Network'}\n";
print "PortName: $object->{'PortName'}\n";
print "Status: $object->{'Status'}\n";
}

This gives me the output below. Does this help you any?
Scott

OUTPUT
------
Caption: Microsoft XPS Document Writer
Device ID: Microsoft XPS Document Writer
Local: 1
Network: 0
PortName: XPSPort:
Status: Unknown
Caption: Microsoft Office Document Image Writer
Device ID: Microsoft Office Document Image Writer
Local: 1
Network: 0
PortName: Microsoft Document Imaging Writer Port:
Status: Unknown
Caption: \\pwm13tms1\CS025790 - color printer
Device ID: \\pwm13tms1\CS025790 - color printer
Local: 0
Network: 1
PortName: 10.78.55.231
Status: Degraded

________________________________________
From: activeperl-bounces@listserv.ActiveState.com [mailto:activeperl-bounce=
s@listserv.ActiveState.com] On Behalf Of Deane.Rothenmaier@walgreens.com
Sent: Wednesday, May 07, 2008 10:35 AM
To: activeperl@listserv.ActiveState.com
Subject: Finding a printer; need help


Gurus, =


Anybody know of a Perl module that can tell me 1. If there's a printer phys=
ically connected to a parallel (or serial) port on a PC and, 2. what printe=
r it is? I've got a project that wants this info, and I've pretty much gott=
en nowhere trying to use WMI (unless I've missed something). In one instanc=
e, it (WMI) identifies seven printers connected to LPT1:, and says that all=
of them are in "Idle" status. Anybody want to assess the accuracy of that =
result? =A0I know, it's just reading the registry (I think); so the informa=
tion I need must be elsewhere. =


True confession time: I'm at a loss here, and in need of your guidance. =


Thanks!!!!!!! =


Deane Rothenmaier
Programmer/Analyst
Walgreens Corp.
847-914-5150

There is something fascinating about science. One gets such wholesale retur=
ns of conjecture out of such a trifling investment of fact. -- Mark Twain

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

RE: Finding a printer; need help

am 07.05.2008 17:57:01 von Deane.Rothenmaier

This is a multipart message in MIME format.
--===============0306511335==
Content-Type: multipart/alternative;
boundary="=_alternative 00579FC886257442_="

This is a multipart message in MIME format.
--=_alternative 00579FC886257442_=
Content-Type: text/plain; charset="US-ASCII"

Scott,

That pretty much gives the same information I got from WMI in my own
attempts (Win32_Printer). It seems to be reading a list of "installed"
printers; which seems to mean "printers that have drivers installed but
are not necessarily physically present." That is, the printers you'd see
in Control Panel/Printers.

What I've been asked to do is report on whether a printer is physically
present, and what printer it is. Note that even something like polling the
LPTx: (or USB_x, or USBx, or COMx:) ports won't work, 'cause I don't think
that would pick up a connected printer that's not turned on. Or will it?
And would it be able to identify it? Don't think so (but I could be
wrong...).

The required output would be something like this:

Port Printer
LPT1: H-P Laserjet 4Si

But if and only if the H-P Laserjet IS ACTUALLY CONNECTED TO port LPT1:.
(Sorry for shouting.)

(Just realized I'm probably beating this into the ground, but it's a
distinction with a difference, one that I need. Sorry...)

Deane Rothenmaier
Programmer/Analyst
Walgreens Corp.
847-914-5150

There is something fascinating about science. One gets such wholesale
returns of conjecture out of such a trifling investment of fact. -- Mark
Twain
--=_alternative 00579FC886257442_=
Content-Type: text/html; charset="US-ASCII"



Scott,



That pretty much gives the same information
I got from WMI in my own attempts (Win32_Printer). It seems to be reading
a list of "installed" printers; which seems to mean "printers
that have drivers installed but are not necessarily physically present."
That is, the printers you'd see in Control Panel/Printers.




What I've been asked to do is report
on whether a printer is physically present, and what printer it is. Note
that even something like polling the LPTx: (or USB_x, or USBx, or COMx:)
ports won't work, 'cause I don't think that would pick up a connected printer
that's not turned on. Or will it? And would it be able to identify it?
 Don't think so (but I could be wrong...).




The required output would be something
like this:




        Port
       Printer


        LPT1:
       H-P Laserjet 4Si




But if and only if the H-P Laserjet
IS ACTUALLY CONNECTED TO port LPT1:.  (Sorry for shouting.)




(Just realized I'm probably beating
this into the ground, but it's a distinction with a difference, one that
I need. Sorry...)




Deane Rothenmaier

Programmer/Analyst

Walgreens Corp.

847-914-5150



There is something fascinating about science. One gets such wholesale returns
of conjecture out of such a trifling investment of fact. -- Mark Twain

--=_alternative 00579FC886257442_=--


--===============0306511335==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============0306511335==--

Re: Finding a printer; need help

am 07.05.2008 20:02:03 von jwkenne

On May 7, 2008, at 11:57 AM, Deane.Rothenmaier@walgreens.com wrote:
> What I've been asked to do is report on whether a printer is
> physically present, and what printer it is. Note that even something
> like polling the LPTx: (or USB_x, or USBx, or COMx:) ports won't
> work, 'cause I don't think that would pick up a connected printer
> that's not turned on. Or will it? And would it be able to identify
> it? Don't think so (but I could be wrong...).


You're being asked to do the impossible. There is no difference
between no printer and a printer turned off. You couldn't tell even in
assembler language. The available options are:

Look for printer queues in the operating system (which may reflect
a long-removed printer, a virtual printer, like a PDF writer or FAX
writer, or a multi-mode printer, a printer that appears to be more
than one printer, such as one PCL and one PostScript.

Look for attached and turned-on printers. If you do this, don't
forget that printers can also connect via Ethernet, etc..

--
John W Kennedy
A proud member of the reality-based community.



_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs