[C#] End Processes

  • Hello Guest! Welcome to ConsoleCrunch, to help support our site check out the premium upgrades HERE! to get exclusive access to our hidden content.
  • Unable to load portions of the website...
    If you use an ad blocker addon, you should disable it because it interferes with several elements of the site and blocks more than just adverts.
  • Read Rules Before Posting Post Virus Scans with every program.

Elite_Modz

Active Poster
Retired Staff
Active Member
Console ID Poster
Dec 19, 2014
517
380
133
Crunch
Update 1

Code:
Code:
public static void EndTask(string taskname)
  {
  string processName = taskname;
  foreach (Process process in Process.GetProcessesByName(processName))
  {
  process.Kill();
  }
  }

Code:
Code:
EndTask(notepad);

Notes:
Program needs admin privelages.
Filetypes such as (.exe) are Not Supported
 
Last edited:

Miss @ Security

Avid Poster
CC Dev Team
Determined Poster
Active Member
Jul 13, 2016
1,040
576
198
Code:
Code:
public static void EndTask(string taskname)
  {
  string processName = taskname;
  Process[] processes = Process.GetProcessesByName(processName);
  foreach (Process process in processes)
  {
  process.Kill();
  }
  }

Code:
Code:
EndTask(notepad);

Notes:
Program needs admin privelages.
You don't need to put .exe at the end of the name.


THANK MATE ;)
 
  • Like
Reactions: Elite_Modz

Elite_Modz

Active Poster
Retired Staff
Active Member
Console ID Poster
Dec 19, 2014
517
380
133
Crunch
Update 2:

Code:
Code:
public static 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();
  }
  }
  }

Code:
Code:
EndTask("notepad");

Notes:
Program needs admin privelages
Fixed: Filetypes such as (.exe) are Now Supported
 
Last edited:

Nostafaru

Moderating the Crunch Bunch.
Retired Staff
Community Elite
Community Veteran
Determined Poster
Active Member
Console ID Poster
Apr 6, 2014
2,020
1,783
443
Update 2:

Code:
Code:
public static void EndTask(string taskname)
  {
  string processName = taskname;

  if (taskname.Contains(".exe"))
  {
  string fixstring = taskname.Replace(".exe", "");
  Process[] processes = Process.GetProcessesByName(fixstring);
  foreach (Process process in processes)
  {
  process.Kill();
  }
  }
  else if (!taskname.Contains(".exe"))
  {
  Process[] processes2 = Process.GetProcessesByName(processName);
  foreach (Process process in processes2)
  {
  process.Kill();
  }
  }
  else
  {

  }
  }

Code:
Code:
EndTask(notepad);

Notes:
Program needs admin privelages
Fixed: Filetypes such as (.exe) are Now Supported

Most of that is totally unnecessary, you could kill a process in just like 3 lines.
 

Elite_Modz

Active Poster
Retired Staff
Active Member
Console ID Poster
Dec 19, 2014
517
380
133
Crunch
Most of that is totally unnecessary, you could kill a process in just like 3 lines.
That's Correct, like so:
Code:
  foreach (Process process in Process.GetProcessesByName("notepad"))
  {
  process.Kill();
  }
 

Nostafaru

Moderating the Crunch Bunch.
Retired Staff
Community Elite
Community Veteran
Determined Poster
Active Member
Console ID Poster
Apr 6, 2014
2,020
1,783
443
That's Correct, like so:
Code:
  foreach (Process process in Process.GetProcessesByName("notepad"))
  {
  process.Kill();
  }
So why all the extra code?
 
General chit-chat
Help Users
    Chat Bot: QM|T_JinX has joined the room.