Kill some processes by .exe file name
up vote
94
down vote
favorite
How can I kill some active processes by searching for their .exe filenames in C# .NET or C++?
c# c++ process exe kill-process
add a comment |
up vote
94
down vote
favorite
How can I kill some active processes by searching for their .exe filenames in C# .NET or C++?
c# c++ process exe kill-process
1
If you need kill process by partial name see stackoverflow.com/questions/14632162/….
– Alexei Levenkov
Sep 18 '14 at 15:22
add a comment |
up vote
94
down vote
favorite
up vote
94
down vote
favorite
How can I kill some active processes by searching for their .exe filenames in C# .NET or C++?
c# c++ process exe kill-process
How can I kill some active processes by searching for their .exe filenames in C# .NET or C++?
c# c++ process exe kill-process
c# c++ process exe kill-process
edited Feb 13 at 5:39
Banee Ishaque K
328316
328316
asked Jul 27 '10 at 15:42
Aliasghar Yaghoobzadeh
471147
471147
1
If you need kill process by partial name see stackoverflow.com/questions/14632162/….
– Alexei Levenkov
Sep 18 '14 at 15:22
add a comment |
1
If you need kill process by partial name see stackoverflow.com/questions/14632162/….
– Alexei Levenkov
Sep 18 '14 at 15:22
1
1
If you need kill process by partial name see stackoverflow.com/questions/14632162/….
– Alexei Levenkov
Sep 18 '14 at 15:22
If you need kill process by partial name see stackoverflow.com/questions/14632162/….
– Alexei Levenkov
Sep 18 '14 at 15:22
add a comment |
4 Answers
4
active
oldest
votes
up vote
180
down vote
accepted
Quick Answer:
foreach (var process in Process.GetProcessesByName("whatever"))
{
process.Kill();
}
(leave off .exe from process name)
3
Thanx so much..
– Aliasghar Yaghoobzadeh
Jul 27 '10 at 16:00
2
what should be do if above code return Exception (a 32 bit processes cannot access modules of a 64 bit process) ?
– Manish
Aug 31 '13 at 11:29
35
Leave off ".exe". From MSDN: "The process name is a friendly name for the process, such as Outlook, that does not include the .exe extension or the path"
– slater
Jun 3 '14 at 16:50
1
@AgainMe Process.Kill() sends a kill signal to a process, which will halt its execution wherever it happens to be. This is different from an interrupt signal in that the process will not have a chance to respond and/or clean up from the signal. No more execution will happen in that process, and any locks on resources used by that process will be released. Environment.Exit() is performed by the currently executing process to kill itself with a success code, which is perfectly safe. Process.Kill() is not nearly as safe as Environment.Exit().
– jchitel
Feb 21 '17 at 2:51
1
I suggest the use of LINQ: var procs = Process.GetProcesses().Where(pr => pr.ProcessName.Contains("Spotify"));
– Leandro Tupone
Jul 18 '17 at 18:33
|
show 3 more comments
up vote
25
down vote
My solution is:
var chromeDriverProcesses = Process.GetProcesses().
Where(pr => pr.ProcessName == "chromedriver");
foreach (var process in chromeDriverProcesses)
{
process.Kill();
}
you could use Contains instead of equal
– Leandro Tupone
Jul 18 '17 at 18:33
6
Funny coincidence is, I was looking in this thread for a solution to killing the chromedriver. Must be a common issue.
– kerl
Aug 9 '17 at 20:08
add a comment |
up vote
13
down vote
You can use Process.GetProcesses()
to get the currently running processes, then Process.Kill()
to kill a process.
6
Process.GetProcessesByName would simplify this.
– ConsultUtah
Jul 27 '10 at 15:50
Thanx so much..
– Aliasghar Yaghoobzadeh
Jul 27 '10 at 16:03
what should be do if above code return Exception (a 32 bit processes cannot access modules of a 64 bit process) ?
– Manish
Aug 31 '13 at 11:29
add a comment |
up vote
-3
down vote
public void EndTask(string taskname)
{
string processName = taskname;
string fixstring = taskname.Replace(".exe", "");
if (taskname.Contains(".exe"))
{
foreach (Process process in Process.GetProcessesByName(fixstring))
{
process.Kill();
}
}
else if (!taskname.Contains(".exe"))
{
foreach (Process process in Process.GetProcessesByName(processName))
{
process.Kill();
}
}
}
//EndTask("notepad");
Summary: No matter if the name contains .exe, the process will end. You don't need to "leave off .exe from process name", It works 100%.
1
a simple.Replace(".exe", "")
on the top voted answer would do this with a lot less convoluted and unnecessary code
– AndrewK
Jan 12 at 22:11
The whole idea of it is to see the method with or without .exe so people can see multiple ways of handling it... It's not meant for copy and paste....
– user7993881
Mar 9 at 2:40
add a comment |
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
180
down vote
accepted
Quick Answer:
foreach (var process in Process.GetProcessesByName("whatever"))
{
process.Kill();
}
(leave off .exe from process name)
3
Thanx so much..
– Aliasghar Yaghoobzadeh
Jul 27 '10 at 16:00
2
what should be do if above code return Exception (a 32 bit processes cannot access modules of a 64 bit process) ?
– Manish
Aug 31 '13 at 11:29
35
Leave off ".exe". From MSDN: "The process name is a friendly name for the process, such as Outlook, that does not include the .exe extension or the path"
– slater
Jun 3 '14 at 16:50
1
@AgainMe Process.Kill() sends a kill signal to a process, which will halt its execution wherever it happens to be. This is different from an interrupt signal in that the process will not have a chance to respond and/or clean up from the signal. No more execution will happen in that process, and any locks on resources used by that process will be released. Environment.Exit() is performed by the currently executing process to kill itself with a success code, which is perfectly safe. Process.Kill() is not nearly as safe as Environment.Exit().
– jchitel
Feb 21 '17 at 2:51
1
I suggest the use of LINQ: var procs = Process.GetProcesses().Where(pr => pr.ProcessName.Contains("Spotify"));
– Leandro Tupone
Jul 18 '17 at 18:33
|
show 3 more comments
up vote
180
down vote
accepted
Quick Answer:
foreach (var process in Process.GetProcessesByName("whatever"))
{
process.Kill();
}
(leave off .exe from process name)
3
Thanx so much..
– Aliasghar Yaghoobzadeh
Jul 27 '10 at 16:00
2
what should be do if above code return Exception (a 32 bit processes cannot access modules of a 64 bit process) ?
– Manish
Aug 31 '13 at 11:29
35
Leave off ".exe". From MSDN: "The process name is a friendly name for the process, such as Outlook, that does not include the .exe extension or the path"
– slater
Jun 3 '14 at 16:50
1
@AgainMe Process.Kill() sends a kill signal to a process, which will halt its execution wherever it happens to be. This is different from an interrupt signal in that the process will not have a chance to respond and/or clean up from the signal. No more execution will happen in that process, and any locks on resources used by that process will be released. Environment.Exit() is performed by the currently executing process to kill itself with a success code, which is perfectly safe. Process.Kill() is not nearly as safe as Environment.Exit().
– jchitel
Feb 21 '17 at 2:51
1
I suggest the use of LINQ: var procs = Process.GetProcesses().Where(pr => pr.ProcessName.Contains("Spotify"));
– Leandro Tupone
Jul 18 '17 at 18:33
|
show 3 more comments
up vote
180
down vote
accepted
up vote
180
down vote
accepted
Quick Answer:
foreach (var process in Process.GetProcessesByName("whatever"))
{
process.Kill();
}
(leave off .exe from process name)
Quick Answer:
foreach (var process in Process.GetProcessesByName("whatever"))
{
process.Kill();
}
(leave off .exe from process name)
edited Nov 12 at 20:02
Valamas
13.9k2286157
13.9k2286157
answered Jul 27 '10 at 15:48
ConsultUtah
4,20032348
4,20032348
3
Thanx so much..
– Aliasghar Yaghoobzadeh
Jul 27 '10 at 16:00
2
what should be do if above code return Exception (a 32 bit processes cannot access modules of a 64 bit process) ?
– Manish
Aug 31 '13 at 11:29
35
Leave off ".exe". From MSDN: "The process name is a friendly name for the process, such as Outlook, that does not include the .exe extension or the path"
– slater
Jun 3 '14 at 16:50
1
@AgainMe Process.Kill() sends a kill signal to a process, which will halt its execution wherever it happens to be. This is different from an interrupt signal in that the process will not have a chance to respond and/or clean up from the signal. No more execution will happen in that process, and any locks on resources used by that process will be released. Environment.Exit() is performed by the currently executing process to kill itself with a success code, which is perfectly safe. Process.Kill() is not nearly as safe as Environment.Exit().
– jchitel
Feb 21 '17 at 2:51
1
I suggest the use of LINQ: var procs = Process.GetProcesses().Where(pr => pr.ProcessName.Contains("Spotify"));
– Leandro Tupone
Jul 18 '17 at 18:33
|
show 3 more comments
3
Thanx so much..
– Aliasghar Yaghoobzadeh
Jul 27 '10 at 16:00
2
what should be do if above code return Exception (a 32 bit processes cannot access modules of a 64 bit process) ?
– Manish
Aug 31 '13 at 11:29
35
Leave off ".exe". From MSDN: "The process name is a friendly name for the process, such as Outlook, that does not include the .exe extension or the path"
– slater
Jun 3 '14 at 16:50
1
@AgainMe Process.Kill() sends a kill signal to a process, which will halt its execution wherever it happens to be. This is different from an interrupt signal in that the process will not have a chance to respond and/or clean up from the signal. No more execution will happen in that process, and any locks on resources used by that process will be released. Environment.Exit() is performed by the currently executing process to kill itself with a success code, which is perfectly safe. Process.Kill() is not nearly as safe as Environment.Exit().
– jchitel
Feb 21 '17 at 2:51
1
I suggest the use of LINQ: var procs = Process.GetProcesses().Where(pr => pr.ProcessName.Contains("Spotify"));
– Leandro Tupone
Jul 18 '17 at 18:33
3
3
Thanx so much..
– Aliasghar Yaghoobzadeh
Jul 27 '10 at 16:00
Thanx so much..
– Aliasghar Yaghoobzadeh
Jul 27 '10 at 16:00
2
2
what should be do if above code return Exception (a 32 bit processes cannot access modules of a 64 bit process) ?
– Manish
Aug 31 '13 at 11:29
what should be do if above code return Exception (a 32 bit processes cannot access modules of a 64 bit process) ?
– Manish
Aug 31 '13 at 11:29
35
35
Leave off ".exe". From MSDN: "The process name is a friendly name for the process, such as Outlook, that does not include the .exe extension or the path"
– slater
Jun 3 '14 at 16:50
Leave off ".exe". From MSDN: "The process name is a friendly name for the process, such as Outlook, that does not include the .exe extension or the path"
– slater
Jun 3 '14 at 16:50
1
1
@AgainMe Process.Kill() sends a kill signal to a process, which will halt its execution wherever it happens to be. This is different from an interrupt signal in that the process will not have a chance to respond and/or clean up from the signal. No more execution will happen in that process, and any locks on resources used by that process will be released. Environment.Exit() is performed by the currently executing process to kill itself with a success code, which is perfectly safe. Process.Kill() is not nearly as safe as Environment.Exit().
– jchitel
Feb 21 '17 at 2:51
@AgainMe Process.Kill() sends a kill signal to a process, which will halt its execution wherever it happens to be. This is different from an interrupt signal in that the process will not have a chance to respond and/or clean up from the signal. No more execution will happen in that process, and any locks on resources used by that process will be released. Environment.Exit() is performed by the currently executing process to kill itself with a success code, which is perfectly safe. Process.Kill() is not nearly as safe as Environment.Exit().
– jchitel
Feb 21 '17 at 2:51
1
1
I suggest the use of LINQ: var procs = Process.GetProcesses().Where(pr => pr.ProcessName.Contains("Spotify"));
– Leandro Tupone
Jul 18 '17 at 18:33
I suggest the use of LINQ: var procs = Process.GetProcesses().Where(pr => pr.ProcessName.Contains("Spotify"));
– Leandro Tupone
Jul 18 '17 at 18:33
|
show 3 more comments
up vote
25
down vote
My solution is:
var chromeDriverProcesses = Process.GetProcesses().
Where(pr => pr.ProcessName == "chromedriver");
foreach (var process in chromeDriverProcesses)
{
process.Kill();
}
you could use Contains instead of equal
– Leandro Tupone
Jul 18 '17 at 18:33
6
Funny coincidence is, I was looking in this thread for a solution to killing the chromedriver. Must be a common issue.
– kerl
Aug 9 '17 at 20:08
add a comment |
up vote
25
down vote
My solution is:
var chromeDriverProcesses = Process.GetProcesses().
Where(pr => pr.ProcessName == "chromedriver");
foreach (var process in chromeDriverProcesses)
{
process.Kill();
}
you could use Contains instead of equal
– Leandro Tupone
Jul 18 '17 at 18:33
6
Funny coincidence is, I was looking in this thread for a solution to killing the chromedriver. Must be a common issue.
– kerl
Aug 9 '17 at 20:08
add a comment |
up vote
25
down vote
up vote
25
down vote
My solution is:
var chromeDriverProcesses = Process.GetProcesses().
Where(pr => pr.ProcessName == "chromedriver");
foreach (var process in chromeDriverProcesses)
{
process.Kill();
}
My solution is:
var chromeDriverProcesses = Process.GetProcesses().
Where(pr => pr.ProcessName == "chromedriver");
foreach (var process in chromeDriverProcesses)
{
process.Kill();
}
answered Dec 27 '13 at 12:47
Arsen Khachaturyan
3,14411621
3,14411621
you could use Contains instead of equal
– Leandro Tupone
Jul 18 '17 at 18:33
6
Funny coincidence is, I was looking in this thread for a solution to killing the chromedriver. Must be a common issue.
– kerl
Aug 9 '17 at 20:08
add a comment |
you could use Contains instead of equal
– Leandro Tupone
Jul 18 '17 at 18:33
6
Funny coincidence is, I was looking in this thread for a solution to killing the chromedriver. Must be a common issue.
– kerl
Aug 9 '17 at 20:08
you could use Contains instead of equal
– Leandro Tupone
Jul 18 '17 at 18:33
you could use Contains instead of equal
– Leandro Tupone
Jul 18 '17 at 18:33
6
6
Funny coincidence is, I was looking in this thread for a solution to killing the chromedriver. Must be a common issue.
– kerl
Aug 9 '17 at 20:08
Funny coincidence is, I was looking in this thread for a solution to killing the chromedriver. Must be a common issue.
– kerl
Aug 9 '17 at 20:08
add a comment |
up vote
13
down vote
You can use Process.GetProcesses()
to get the currently running processes, then Process.Kill()
to kill a process.
6
Process.GetProcessesByName would simplify this.
– ConsultUtah
Jul 27 '10 at 15:50
Thanx so much..
– Aliasghar Yaghoobzadeh
Jul 27 '10 at 16:03
what should be do if above code return Exception (a 32 bit processes cannot access modules of a 64 bit process) ?
– Manish
Aug 31 '13 at 11:29
add a comment |
up vote
13
down vote
You can use Process.GetProcesses()
to get the currently running processes, then Process.Kill()
to kill a process.
6
Process.GetProcessesByName would simplify this.
– ConsultUtah
Jul 27 '10 at 15:50
Thanx so much..
– Aliasghar Yaghoobzadeh
Jul 27 '10 at 16:03
what should be do if above code return Exception (a 32 bit processes cannot access modules of a 64 bit process) ?
– Manish
Aug 31 '13 at 11:29
add a comment |
up vote
13
down vote
up vote
13
down vote
You can use Process.GetProcesses()
to get the currently running processes, then Process.Kill()
to kill a process.
You can use Process.GetProcesses()
to get the currently running processes, then Process.Kill()
to kill a process.
answered Jul 27 '10 at 15:45
driis
120k40232315
120k40232315
6
Process.GetProcessesByName would simplify this.
– ConsultUtah
Jul 27 '10 at 15:50
Thanx so much..
– Aliasghar Yaghoobzadeh
Jul 27 '10 at 16:03
what should be do if above code return Exception (a 32 bit processes cannot access modules of a 64 bit process) ?
– Manish
Aug 31 '13 at 11:29
add a comment |
6
Process.GetProcessesByName would simplify this.
– ConsultUtah
Jul 27 '10 at 15:50
Thanx so much..
– Aliasghar Yaghoobzadeh
Jul 27 '10 at 16:03
what should be do if above code return Exception (a 32 bit processes cannot access modules of a 64 bit process) ?
– Manish
Aug 31 '13 at 11:29
6
6
Process.GetProcessesByName would simplify this.
– ConsultUtah
Jul 27 '10 at 15:50
Process.GetProcessesByName would simplify this.
– ConsultUtah
Jul 27 '10 at 15:50
Thanx so much..
– Aliasghar Yaghoobzadeh
Jul 27 '10 at 16:03
Thanx so much..
– Aliasghar Yaghoobzadeh
Jul 27 '10 at 16:03
what should be do if above code return Exception (a 32 bit processes cannot access modules of a 64 bit process) ?
– Manish
Aug 31 '13 at 11:29
what should be do if above code return Exception (a 32 bit processes cannot access modules of a 64 bit process) ?
– Manish
Aug 31 '13 at 11:29
add a comment |
up vote
-3
down vote
public void EndTask(string taskname)
{
string processName = taskname;
string fixstring = taskname.Replace(".exe", "");
if (taskname.Contains(".exe"))
{
foreach (Process process in Process.GetProcessesByName(fixstring))
{
process.Kill();
}
}
else if (!taskname.Contains(".exe"))
{
foreach (Process process in Process.GetProcessesByName(processName))
{
process.Kill();
}
}
}
//EndTask("notepad");
Summary: No matter if the name contains .exe, the process will end. You don't need to "leave off .exe from process name", It works 100%.
1
a simple.Replace(".exe", "")
on the top voted answer would do this with a lot less convoluted and unnecessary code
– AndrewK
Jan 12 at 22:11
The whole idea of it is to see the method with or without .exe so people can see multiple ways of handling it... It's not meant for copy and paste....
– user7993881
Mar 9 at 2:40
add a comment |
up vote
-3
down vote
public void EndTask(string taskname)
{
string processName = taskname;
string fixstring = taskname.Replace(".exe", "");
if (taskname.Contains(".exe"))
{
foreach (Process process in Process.GetProcessesByName(fixstring))
{
process.Kill();
}
}
else if (!taskname.Contains(".exe"))
{
foreach (Process process in Process.GetProcessesByName(processName))
{
process.Kill();
}
}
}
//EndTask("notepad");
Summary: No matter if the name contains .exe, the process will end. You don't need to "leave off .exe from process name", It works 100%.
1
a simple.Replace(".exe", "")
on the top voted answer would do this with a lot less convoluted and unnecessary code
– AndrewK
Jan 12 at 22:11
The whole idea of it is to see the method with or without .exe so people can see multiple ways of handling it... It's not meant for copy and paste....
– user7993881
Mar 9 at 2:40
add a comment |
up vote
-3
down vote
up vote
-3
down vote
public void EndTask(string taskname)
{
string processName = taskname;
string fixstring = taskname.Replace(".exe", "");
if (taskname.Contains(".exe"))
{
foreach (Process process in Process.GetProcessesByName(fixstring))
{
process.Kill();
}
}
else if (!taskname.Contains(".exe"))
{
foreach (Process process in Process.GetProcessesByName(processName))
{
process.Kill();
}
}
}
//EndTask("notepad");
Summary: No matter if the name contains .exe, the process will end. You don't need to "leave off .exe from process name", It works 100%.
public void EndTask(string taskname)
{
string processName = taskname;
string fixstring = taskname.Replace(".exe", "");
if (taskname.Contains(".exe"))
{
foreach (Process process in Process.GetProcessesByName(fixstring))
{
process.Kill();
}
}
else if (!taskname.Contains(".exe"))
{
foreach (Process process in Process.GetProcessesByName(processName))
{
process.Kill();
}
}
}
//EndTask("notepad");
Summary: No matter if the name contains .exe, the process will end. You don't need to "leave off .exe from process name", It works 100%.
edited Jun 9 '17 at 21:19
answered Jun 9 '17 at 20:59
user7993881
111
111
1
a simple.Replace(".exe", "")
on the top voted answer would do this with a lot less convoluted and unnecessary code
– AndrewK
Jan 12 at 22:11
The whole idea of it is to see the method with or without .exe so people can see multiple ways of handling it... It's not meant for copy and paste....
– user7993881
Mar 9 at 2:40
add a comment |
1
a simple.Replace(".exe", "")
on the top voted answer would do this with a lot less convoluted and unnecessary code
– AndrewK
Jan 12 at 22:11
The whole idea of it is to see the method with or without .exe so people can see multiple ways of handling it... It's not meant for copy and paste....
– user7993881
Mar 9 at 2:40
1
1
a simple
.Replace(".exe", "")
on the top voted answer would do this with a lot less convoluted and unnecessary code– AndrewK
Jan 12 at 22:11
a simple
.Replace(".exe", "")
on the top voted answer would do this with a lot less convoluted and unnecessary code– AndrewK
Jan 12 at 22:11
The whole idea of it is to see the method with or without .exe so people can see multiple ways of handling it... It's not meant for copy and paste....
– user7993881
Mar 9 at 2:40
The whole idea of it is to see the method with or without .exe so people can see multiple ways of handling it... It's not meant for copy and paste....
– user7993881
Mar 9 at 2:40
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f3345363%2fkill-some-processes-by-exe-file-name%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
If you need kill process by partial name see stackoverflow.com/questions/14632162/….
– Alexei Levenkov
Sep 18 '14 at 15:22