473,407 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Getting The Process ID for an Executable Path

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
2 9623
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Steve | last post by:
I need help. I'm trying to write a process wrapper class in Python (on Linux) that let's one: - read service definitions from a config file (where a service definition includes a bash command to...
15
by: songie D | last post by:
H If I us Process.Start("DTSRun ...") on a computer that has SQL server installed, it can't fin DTSRun, claiming 'file not found'. Despite this, Shell("DTSRun...") from VB.NET works fine It also...
1
by: john conwell | last post by:
I've got a process engine written in .Net. the user writes a data file and saves it as file type ".xyz". I have a file assiciation set up in the database that when a .xyz file is invoked (double...
4
by: Dave | last post by:
I am writing a C# app in which I need to enumerate the processes running on the PC. I have succesfully done this as follows (assuming the app is running on NT4, XP, 2000 or 2003): ...
1
by: Robert | last post by:
Hello, I am doing an automatic backup service using c# and VS2003. To achieve this i must call an executable file. So far I have made it all work using Process, code looks like this: ...
0
by: pigeonrandle | last post by:
Hi, I have used GetProcessImageFileName() to get the executable path of a process. It returns '\Device\HardiskVolume1' at the beginning of the path. How on earth do i find out what the actual...
1
by: Adam Atlas | last post by:
What is the best way for a Python process (presumed to be a script run by the interpreter binary, not embedded in some other program) to restart itself? This is what I've been trying: import...
0
by: BruceMcF | last post by:
On Apr 16, 6:03 pm, "Aaron Gray" <ang.use...@gmail.comwrote:
4
by: Kerem Gümrükcü | last post by:
Hi, i wonder that the Process.Start(...) needs full path to the executable to start it, even the executable is listed in the PATH Variable and can be launched from any console on my system. Is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.