DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

David has posted 23 posts at DZone. View Full User Profile

Using Ruby & WMI To Get Win32 Process Information

07.08.2007
| 6919 views |
  • submit to reddit
        From the <a href="http://rubyonwindows.blogspot.com/">Ruby on Windows</a> blog...

Use Windows Management Instrumentation (WMI) to get information about the Win32 processes being run.
require 'win32ole'

wmi = WIN32OLE.connect("winmgmts://")

processes = wmi.ExecQuery("select * from win32_process")

for process in processes do
    puts "Name: #{process.Name}"
    puts "CommandLine: #{process.CommandLine}"
    puts "CreationDate: #{process.CreationDate}"
    puts "WorkingSetSize: #{process.WorkingSetSize}"
    puts
end
Further details and discussion <a href="http://rubyonwindows.blogspot.com/2007/07/using-ruby-wmi-to-get-win32-process.html">here</a>.