餐厅包间挂什么字好:ruby在windows下杀进程的方法

来源:百度文库 编辑:偶看新闻 时间:2024/04/29 17:12:54

ruby在windows下杀进程的方法

.Xgv724 { display:none; }
1.用OLE

Ruby代码 
require "win32ole"
mgmt = WIN32OLE.connect('winmgmts:\\\\.')
mgmt.ExecQuery("Select * from Win32_Process Where Name ='#{proc_name}'").each{ |item|
item.Terminate()
}

require "win32ole"
mgmt = WIN32OLE.connect('winmgmts:\\\\.')
mgmt.ExecQuery("Select * from Win32_Process Where Name ='#{proc_name}'").each{ |item|
item.Terminate()
}
2.不用OLE

Ruby代码  
require 'sys/proctable'
require 'time'

Sys::ProcTable.ps.each { |ps|
if ps.name.downcase == proc_name.downcase
Process.kill('KILL', ps.pid)
end
}

require 'sys/proctable'
require 'time'

Sys::ProcTable.ps.each { |ps|
if ps.name.downcase == proc_name.downcase
Process.kill('KILL', ps.pid)
end
}