Ruby关闭IE进程采用直接关闭进程法

在Ruby语言的实际是代码编写中,我们会觉得它的编写方式不同于其他语言,并且在编写代码时会有一种非常愉悦的心情。在这里我们就为大家介绍一下Ruby关闭IE进程的相关方法。#t#

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

 

 

  1. require 'win32ole'  
  2. # Returns the number 
    of windows
     processes running with
     the specified name.  
  3. def close_ie  
  4. mgmt = WIN32OLE.connect
    ('winmgmts:\\\\.')  
  5. processes=mgmt.
    instancesof("win32_process")  
  6. processes.each do |process|  
  7. puts process  
  8. if process.name ==
    "iexplore.exe" then   
  9. process.terminate()  
  10. end  
  11. end  
  12. end  

 

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

THE END