Boiko
Member
Hi all,
just trying to create simple console which can take user input and kill process which was typed. i've created this small application which does what it should:
What i want to do is to kill certain processes by folder/ path name, but i don't want to specify whole path. So for example i have c:\program\mario1\mario.exe, c:\program\mario2\mario.exe etc and there is 10 of them and i want to terminate just one from mario1 folder? i know i should use loop on it, but just don't know how to implement in my code, just need a bit more practice i guess!
Thanks,
Tomas
just trying to create simple console which can take user input and kill process which was typed. i've created this small application which does what it should:
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace ConsoleApp14
{
class Program
{
static void Main(string[] args)
{
// Store all running process in the system
Process[] runningProcess = Process.GetProcesses();
Console.Write("Please enter your process name: ");
string userInput = Console.ReadLine();
for (int i =0; i < runningProcess.Length; i++)
{
if (runningProcess[i].ProcessName == userInput )
{
Console.WriteLine("We found your process {0} and it was terminated!" , userInput);
runningProcess[i].Kill();
}
}
Console.ReadLine();
}
}
}
What i want to do is to kill certain processes by folder/ path name, but i don't want to specify whole path. So for example i have c:\program\mario1\mario.exe, c:\program\mario2\mario.exe etc and there is 10 of them and i want to terminate just one from mario1 folder? i know i should use loop on it, but just don't know how to implement in my code, just need a bit more practice i guess!
Thanks,
Tomas