Hi everybody, i'm working on Microsoft Windows XP, and i want to make a
program to kill windows process by the name of the process, not by the PID,
like EXCEL.EXE to kill microsoft excel or IEXPLORE.EXE to kill Internet
Explorer.
At this moment, i'm using this code:
mgmt = WIN32OLE.connect('winmgmts:\\\\.')
mgmt.ExecQuery("Select * from Win32_Process Where Name =
'#{proc_name}'").each{ |item|
item.Terminate()
}
It works, but sometimes it crashes, in an inesperated way.
Hi everybody, i'm working on Microsoft Windows XP, and i want to make a
program to kill windows process by the name of the process, not by the PID,
like EXCEL.EXE to kill microsoft excel or IEXPLORE.EXE to kill Internet
Explorer.
At this moment, i'm using this code:
mgmt = WIN32OLE.connect('winmgmts:\\\\.')
mgmt.ExecQuery("Select * from Win32_Process Where Name =
'#{proc_name}'").each{ |item|
item.Terminate()
}
It works, but sometimes it crashes, in an inesperated way.
Here's a way that works well here, doesn't use OLE, and is even a sort
of portable
require 'sys/proctable'
require 'time'
Sys::ProcTable.ps.each { |ps|
if ps.name.downcase == proc_name.downcase
Process.kill('KILL', ps.pid)
end
}
I'm not using win myself. But I've seen an example on killing processes in Win
in Managing Projects with GUN Make, from O'Reilly
···
On 17 jan 2008, at 14.54, Agustin Ramos wrote:
Hi everybody, i'm working on Microsoft Windows XP, and i want to make a
program to kill windows process by the name of the process, not by the PID,
like EXCEL.EXE to kill microsoft excel or IEXPLORE.EXE to kill Internet
Explorer.
At this moment, i'm using this code:
mgmt = WIN32OLE.connect('winmgmts:\\\\.')
mgmt.ExecQuery("Select * from Win32_Process Where Name =
'#{proc_name}'").each{ |item|
item.Terminate()
}
It works, but sometimes it crashes, in an inesperated way.
Thanks and i'm waiting for your help.
Agustin Ramos
-----------------------------------
See the amazing new SF reel: Invasion of the man eating cucumbers from outer space.
On congratulations for a fantastic parody, the producer replies : "What parody?"
Hi everybody, i'm working on Microsoft Windows XP, and i want to make a
program to kill windows process by the name of the process, not by the
PID,
like EXCEL.EXE to kill microsoft excel or IEXPLORE.EXE to kill Internet
Explorer.
At this moment, i'm using this code:
mgmt = WIN32OLE.connect('winmgmts:\\\\.')
mgmt.ExecQuery("Select * from Win32_Process Where Name =
'#{proc_name}'").each{ |item|
item.Terminate()
}
It works, but sometimes it crashes, in an inesperated way.