使用WMI获取windows进程信息

本例主要实现如何用WMI(Windows Management Instrumentation )获取windows进程信息。

 

首先,需要用到win32ole。

 

require 'win32ole'

 

具体实现:

 

    wmi = WIN32OLE.connect("winmgmts://")
    processes = wmi.ExecQuery("select * from win32_process")
    processes.each do |process|
      puts "Name: #{process.Name}"
      puts "CommandLine: #{process.CommandLine}"
      puts "CreationDate: #{process.CreationDate}"
      puts "WorkingSetSize: #{process.WorkingSetSize}"
      puts
    end

 

示例输出:

 

Name: System Idle Process
CommandLine: 
CreationDate: 
WorkingSetSize: 28672

Name: System
CommandLine: 
CreationDate: 
WorkingSetSize: 311296

Name: smss.exe
CommandLine: \SystemRoot\System32\smss.exe
CreationDate: 20100108194948.296875+480
WorkingSetSize: 835584

Name: csrss.exe
CommandLine: 
CreationDate: 20100108194952.468750+480
WorkingSetSize: 12623872

Name: winlogon.exe
CommandLine: winlogon.exe
CreationDate: 20100108194954.437500+480
WorkingSetSize: 31866880

 

你可能感兴趣的:(windows)