110,534
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace ConsoleApplication
{
class Program
{
[DllImport("kernel32.dll")]
public static extern int WaitForSingleObject(int hHandle, uint dwMilliseconds);
const uint INFINITE = 0xFFFFFFFF;
static void Main(string[] args)
{
int ret = 0;
while (true)
{
if (Process.GetProcesses().FirstOrDefault(p => p.MainModule.ModuleName == "a.exe") != null)
{
Process p = Process.GetProcesses().FirstOrDefault(o => o.MainModule.ModuleName == "a.exe");
int hHandle = (int)p.Handle;
ret = WaitForSingleObject(hHandle, INFINITE);
if (ret == 0)
{
Process.Start(@"d:\a.exe");
}
}
else
{
Process.Start(@"d:\a.exe");
}
}
}
}
}
string[] names = ProcessNames.Split(new char[] { ',' });
foreach (string name in names)
{
Process[] process = System.Diagnostics.Process.GetProcessesByName(name, Environment.MachineName);
foreach (Process pro in process)
{
pro.Kill();
WriteActionLog("The process " + pro.ProcessName + " has been killed!");
}
process = null;
}