Forum: Ruby Re: Getting a list of Processes

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Peña, Botp (Guest)
on 2006-06-12 06:20
(Received via mailing list)
fr Brad:
# Sure, no problem... also, you can list more than the process name. I
# like to show the PID and the executablepath, etc. Here are
# other process
# items you might like to examine:
#
# class Win32_Process : CIM_Process
# {
#   string Caption;
#   string CommandLine;
# ...

it would be nice if a particular ruby win32ole method can expose all
those attributes without looking thru msdn docs, no? similar to an ole
browser yet in ruby lib format..

thanks and kind regards -botp
Brad (Guest)
on 2006-06-12 15:28
Peña, Botp wrote:

> it would be nice if a particular ruby win32ole method can expose all
> those attributes without looking thru msdn docs, no? similar to an ole
> browser yet in ruby lib format..
>
> thanks and kind regards -botp

I agree. I do it in Python (with the wmi module) like this:

c = wmi.WMI()
for item in c.Win32_Process():
    print item

I don't know who to contact about it. Is there a formal request process
for Ruby additions someplace?
Reggie M. (Guest)
on 2006-06-13 10:41
Peña, Botp wrote:
> fr Brad:
> # Sure, no problem... also, you can list more than the process name. I
> # like to show the PID and the executablepath, etc. Here are
> # other process
> # items you might like to examine:
> #
> # class Win32_Process : CIM_Process
> # {
> #   string Caption;
> #   string CommandLine;
> # ...
>
> it would be nice if a particular ruby win32ole method can expose all
> those attributes without looking thru msdn docs, no? similar to an ole
> browser yet in ruby lib format..
>

Here it is...I think this is what you were looking for.
It displays all of the properties for a WMI Class.

require 'win32ole'

class MyClass
def get_process_info()
  procs = WIN32OLE.connect("winmgmts:\\\\.")
    rst = procs.ExecQuery("SELECT * FROM meta_class WHERE __class =
'Win32_Process'")
    rst.each do |x|
        puts x.path_.Class.to_s  #The Class Name
        x.properties_.each do |m|
          puts "  " + m.Name.to_s  #Available Properties of this Class
        end
    end
end
end

a = MyClass.new
a.get_process_info()
This topic is locked and can not be replied to.