By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,361 Members | 1,700 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,361 IT Pros & Developers. It's quick & easy.

Getting The Process ID for an Executable Path

P: n/a
Hello,

I have a need to kill a process. It sounds each enough, but the problem is
that I have multiple executables running from different paths. Say, I have
MyService.exe running from C:\FolderA and the same MyService.exe running in
C:\FolderB. I want to kill the process that is running under C:\FolderA. So
I guess I have a need to get the Process ID for the executable under
C:\FolderA.

How can I kill the process when you know the path to the executable?

TIA
Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
I'd use the registry or a textfile. Have each process create a key with
its' path and use the process ID for the value (after it's started). When
you kill the process delete the key. If you want to use a textfile, then
put it in %tmp% and have it track the path of all executables and process
ids. The textfile is probably the more difficult route.

On Thu, 2 Sep 2004 16:21:05 -0700, Hayato Iriumi <hi*****@hotmail.com>
wrote:
Hello,

I have a need to kill a process. It sounds each enough, but the problem
is
that I have multiple executables running from different paths. Say, I
have
MyService.exe running from C:\FolderA and the same MyService.exe running
in
C:\FolderB. I want to kill the process that is running under C:\FolderA.
So
I guess I have a need to get the Process ID for the executable under
C:\FolderA.

How can I kill the process when you know the path to the executable?

TIA


Nov 16 '05 #2

P: n/a
ew... I personally don't like that.

I did though came up with this piece of code. Answer to my own question...

public static void KillProcess(string ExecutablePath)

{

string strTargetProcessName =
System.IO.Path.GetFileNameWithoutExtension(Executa blePath);

Process[] Processes = Process.GetProcessesByName(strTargetProcessName);

foreach(Process p in Processes)

{

foreach(ProcessModule m in p.Modules)

{

if(ExecutablePath.ToLower() == m.FileName.ToLower())

{

p.Kill();

return;

}

}
}

}

"Derek Griffiths" <met.n.ospam@gmail> wrote in message
news:op**************@derek.workgroup...
I'd use the registry or a textfile. Have each process create a key with
its' path and use the process ID for the value (after it's started). When
you kill the process delete the key. If you want to use a textfile, then
put it in %tmp% and have it track the path of all executables and process
ids. The textfile is probably the more difficult route.

On Thu, 2 Sep 2004 16:21:05 -0700, Hayato Iriumi <hi*****@hotmail.com>
wrote:
Hello,

I have a need to kill a process. It sounds each enough, but the problem
is
that I have multiple executables running from different paths. Say, I
have
MyService.exe running from C:\FolderA and the same MyService.exe running
in
C:\FolderB. I want to kill the process that is running under C:\FolderA.
So
I guess I have a need to get the Process ID for the executable under
C:\FolderA.

How can I kill the process when you know the path to the executable?

TIA

Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.