# Get pending jobs

**URL:** <https://www.ruby-forum.com/t/get-pending-jobs/130461>\
**Category:** Ruby\
**Created:** [February 28, 2008, 1:30pm UTC](https://www.ruby-forum.com/t/get-pending-jobs/130461 "2008-02-28T13:30:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![crazybass](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eb9ed0/32.png) [@crazybass](https://www.ruby-forum.com/u/crazybass)\
**Post date:** [February 28, 2008, 1:30pm UTC](https://www.ruby-forum.com/t/get-pending-jobs/130461/1 "2008-02-28T13:30:59Z")

</div>

Hello

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

Thanks

regards

---

<div class="post-metadata">

**Author:** ![crazybass](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eb9ed0/32.png) [@crazybass](https://www.ruby-forum.com/u/crazybass)\
**Post date:** [February 28, 2008, 2:08pm UTC](https://www.ruby-forum.com/t/get-pending-jobs/130461/2 "2008-02-28T14:08:20Z")

</div>

On Thu, Feb 28, 2008 at 1:30 PM, Paulo C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

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

---

<div class="post-metadata">

**Author:** ![crazybass](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eb9ed0/32.png) [@crazybass](https://www.ruby-forum.com/u/crazybass)\
**Post date:** [February 28, 2008, 4:08pm UTC](https://www.ruby-forum.com/t/get-pending-jobs/130461/3 "2008-02-28T16:08:19Z")

</div>

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

Jano S. wrote:

> On Thu, Feb 28, 2008 at 1:30 PM, Paulo C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > 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.

---

<div class="post-metadata">

**Author:** ![crazybass](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eb9ed0/32.png) [@crazybass](https://www.ruby-forum.com/u/crazybass)\
**Post date:** [February 28, 2008, 6:36pm UTC](https://www.ruby-forum.com/t/get-pending-jobs/130461/4 "2008-02-28T18:36:53Z")

</div>

On Thu, Feb 28, 2008 at 9:08 AM, Paulo C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> 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](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:  
`
require ‘ruby-wmi’`

`
`

`WMI::Win32_PrintJob.find(:all).each{ |job|
job.properties_.each{ |prop|
puts “#{prop.name}: #{job[prop.name]}”
}
}
`  
  
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:

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:

`
require 'ruby-wmi'
`

`WMI::Win32_PrintJob.find(:all).each{ |job|
puts “Name: #{job.name}”
puts “PagesPrinted: #{job.PagesPrinted}”
puts “TotalPages: #{job.TotalPages}”
}
`

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

Hope that helps.

Gordon
