Завершение указанного процесса
Категория: .NET
2011-09-07 00:10:23
code: #csharp
- static public bool IsProcessOpen(string name)
- {
- return Process.GetProcesses().Any(clsProcess => clsProcess.ProcessName.ToLower().Contains(name.ToLower()));
- }
- static public bool FindAndKillProcess(string[] names)
- {
- var killedProcesses = 0;
- foreach (var clsProcess in from name in names
- from clsProcess in Process.GetProcesses()
- where clsProcess.ProcessName.ToLower().Contains(name.ToLower())
- select clsProcess)
- {
- clsProcess.Kill();
- killedProcesses++;
- if (killedProcesses == names.Length)
- return true;
- }
- return false;
- }
- static void Main()
- {
- var processesToKill = new[] { "note", "akel" };
- if (IsProcessOpen("winam"))
- if (IsProcessOpen("not"))
- FindAndKillProcess(processesToKill);
- }
Поделиться: