Getting a list of Processes

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

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:

···

--
Posted via http://www.ruby-forum.com/\.