ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> activeperl
activeperl
RE: Finding a printer; need help
by Scott Campbell other posts by this author
May 7 2008 8:30AM messages near this date
Finding a printer; need help | RE: Finding a printer; need help
Deane, try these lines of Perl for WMI:

use Win32::OLE qw(in with);

$WMI = Win32::OLE-> new('WbemScripting.SWbemLocator');
$Services = $WMI-> ConnectServer("", "root/cimv2");
my $Printer_set = $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@[...].com [mailto:activeperl-bounces@[...].com] On Behalf Of Deane.
Rothenmaier@[...].com
Sent: Wednesday, May 07, 2008 10:35 AM
To: activeperl@[...].com
Subject: Finding a printer; need help


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 w
ants this info, and I've pretty much gotten nowhere trying to use WMI (unless I've missed so
mething). In one instance, it (WMI) identifies seven printers connected to LPT1:, and says t
hat 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 elsewher
e. 

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

_______________________________________________
ActivePerl mailing list
ActivePerl@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Deane Rothenmaier
Scott Campbell
Deane Rothenmaier
John W Kennedy

Privacy Policy | Email Opt-out | Feedback | Syndication
© 2004 ActiveState, a division of Sophos All rights reserved