Get pending jobs

P

Paulo Carvalho

Hello

I would like to know how can I get the list of pending jobs in a given
printer queue with ruby.

Thanks

regards
 
J

Jano Svitok

Hello

I would like to know how can I get the list of pending jobs in a given
printer queue with ruby.

Thanks

regards

Please post your operating system type and version/what kind of
printer queue - local, remote, etc. Be specific,
tell more details. Try to imagine you're someone else reading your
mail (omit the words 'with ruby') and try to answer it.
You see?

J.
 
P

Paulo Carvalho

Sorry, you are right.

I am working on a windows environment (my rails server is installed on a
windows 2000 machine). With my rails server I would like to get a list
of the jobs which are currently being processed in a printer (local or
network printer).
What is the best way to get this kink of information?

regards
 
G

Gordon Thiesfeld

Sorry, you are right.

I am working on a windows environment (my rails server is installed on a
windows 2000 machine). With my rails server I would like to get a list
of the jobs which are currently being processed in a printer (local or
network printer).
What is the best way to get this kink of information?

regards

The Win32_PrintJob WMI class will provide this information. You can
access WMI in Ruby using win32ole. Here's a link to a page with a
vbscript example.

http://www.microsoft.com/technet/scriptcenter/guide/sas_prn_owev.mspx?mfr=true


You can also use my Ruby-WMI gem, which wraps win32ole and provides an
API similar to ActiveRecord. Here are some code samples:
<code>
require 'ruby-wmi'

WMI::Win32_PrintJob.find:)all).each{ |job|
job.properties_.each{ |prop|
puts "#{prop.name}: #{job[prop.name]}"
}
}
</code>
<output>
Caption: \\server\printer, 191
DataType: RAW
Description: \\server\printer, 191
Document: document.pdf
DriverName: HP LaserJet 4250 PS
ElapsedTime: 00000000000000.000000:000
HostPrintQueue: \\10.1.53.7
InstallDate:
JobId: 191
JobStatus:
Name: \\server\printer, 191
Notify: gthiesfeld
Owner: gthiesfeld
PagesPrinted: 0
Parameters:
PrintProcessor: hpzpp38Y
Priority: 1
Size: 495840
StartTime:
Status: UNKNOWN
StatusMask: 0
TimeSubmitted: 20080228111424.908000-360
TotalPages: 3
UntilTime:
</output>

This uses the properties_ method to iterate through all of the
properties and spits them out. Once you know which properties you
want to use, you can replace them, like so:

<code>
require 'ruby-wmi'

WMI::Win32_PrintJob.find:)all).each{ |job|
puts "Name: #{job.name}"
puts "PagesPrinted: #{job.PagesPrinted}"
puts "TotalPages: #{job.TotalPages}"
}
</code>
<output>

Name: \\server\printer, 191
PagesPrinted: 0
TotalPages: 3

</output>

Hope that helps.

Gordon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,285
Messages
2,571,416
Members
48,107
Latest member
jigyasauniversity

Latest Threads

Top