Код, проверяющий наличие программы в процессах
Категория: .NET
2011-09-05 23:51:32
code: #csharp
- using System;
- using System.Diagnostics;
- namespace FindMyProcess
- {
- class Program
- {
- static string process_name = "uTorrent"; //Имя процесса
- static void Main()
- {
- System.Timers.Timer time = new System.Timers.Timer(1000);
- time.Enabled = true;
- time.Elapsed += new System.Timers.ElapsedEventHandler(time_Elapsed);
- time.Start();
- Console.ReadLine();
- }
- static void time_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
- {
- Process[] process = Process.GetProcesses();
- foreach (Process p in process)
- {
- if (p.ProcessName.Equals(process_name))
- {
- Console.WriteLine("Процесс {0} жив.", process_name);
- return;
- }
- }
- Console.WriteLine("Процесс {0} мертв.", process_name);
- }
- }
- }
code: #csharp
- static void time_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
- {
- Process[] process = Process.GetProcessesByName(process_name, Environment.MachineName);
- if (process.Length > 0)
- {
- Console.WriteLine("Процесс {0} жив.", process_name);
- return;
- }
- Console.WriteLine("Процесс {0} мертв.", process_name);
- }
Поделиться: