使用ruby关闭ie进程

使用watir的close_all方法,有时会关闭不掉IE,最好的办法就是直接终止IE进程,可以写一个关闭ie的方法

require 'win32ole'

# Returns the number of windows processes running with the specified name.

def close_ie

mgmt = WIN32OLE.connect('winmgmts:\\\\.')

processes=mgmt.instancesof("win32_process")

processes.each do |process|

puts process

if process.name =="iexplore.exe" then

process.terminate()

end

end

end

这样调用close_ie方法时就可以关闭IE进程了。