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-13 13:12
(Received via mailing list)
fr Reggie Mr:

# 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()

cool, Reggie. Thanks much.

I've modified it a bit, if u don't mind.

#-------
class WMI
   require 'win32ole'

   def initialize
      @procs = WIN32OLE.connect("winmgmts:\\\\.")
   end

   def get_class(wmi_class)
      rst = @procs.ExecQuery("SELECT * FROM meta_class WHERE __class =
'#{wmi_class}'")
      rst.each do |x|
         x.properties_.each do |m|
            yield m if block_given?
         end
      end
   end
end


a = WMI.new

puts "---get process names----"
a.get_class("Win32_Process") do |cl|
   puts cl.name
end

puts "---get registry names----"
a.get_class("Win32_Registry") do |cl|
   puts cl.name
end
#----

I have a problem though, how do i get other properties besides the name,
eg cl.name, i tried cl.description but it does not work.
sorry if this is too simple. i do not do windows programming.

kind regards -botp
2714e05018e549d252754fd77dacc9e1?d=identicon&s=25 Reggie M. (rpw)
on 2006-06-13 13:50
>
> I have a problem though, how do i get other properties besides the name,
> eg cl.name, i tried cl.description but it does not work.
> sorry if this is too simple. i do not do windows programming.
>
> kind regards -botp

The only other property values avialable are:
CIMType 	Type of this property.
IsArray 	Boolean value that indicates if this property has an array
type.
IsLocal 	Boolean value that indicates if this property is local.
Name 	        Name of this WMI property.
Origin 	        Contains the originating class of this property.
Qualifiers 	An SWbemQualifierSet object, which is the collection of
qualifiers
                for this property.
Value 	        Actual value of this property. This is the default
automation
                property of this object.

It's available at this link:

http://msdn.microsoft.com/library/default.asp?url=...
This topic is locked and can not be replied to.