欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

使用WMI获取windows进程信息

程序员文章站 2022-03-03 13:50:12
...

本例主要实现如何用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