Kill Process by it's name

A

Agustin Ramos

[Note: parts of this message were removed to make it a legal post.]

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
 
M

Mikel Lindsaar

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,

I am not sure if it works on XP, but it definitely works on Windows Server 2003:

`taskkill /im excel.exe /f`

I use it to kill off zombie processes.

Warning though, this will kill ANYTHING that matches the image name of
excel.exe... that is, all copies running.

Regards

Mikel
 
P

Phlip

Agustin said:
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.

That is a Win32 kernel question, so if this doesn't help, repost to a win32
kernel forum.

http://www.interactivecode.com/programming-coding-1/re-need-function-kill-program-1094/

That's my port of 'killall' to the PSAPI.LIB. It might crash differently from
yours. If you can't port it to WIN32 calls, you might compile it with a C++
compiler, then shell to it with system('').

Ask here if you get stuck!
 
L

Lars

Agustin said:
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
}
 
T

Tommy Nordgren

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
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
-----------------------------------
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?"

Tommy Nordgren
(e-mail address removed)
 
L

luis lopez

[Note: parts of this message were removed to make it a legal post.]

agustin t amoooo!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,262
Messages
2,571,049
Members
48,769
Latest member
Clifft

Latest Threads

Top