public static StringBuilder sb = new StringBuilder();
public static bool Start(List<string> pro)
{
bool result = false;
try
{
foreach (var proName in pro)
{
Process[] proA = Process.GetProcessesByName(proName);
if (proA.Length > 0)
{
foreach (var proEvery in proA)
{
proEvery.Kill();
// Thread.Sleep(2000);
proEvery.Start();
sb.Append(proName + "已启动\r\n");
//Console.WriteLine(proName + "已启动");
}
}
else
{
Process processNew = Process.Start(proName);
sb.Append(proName + "已启动\r\n");
//Console.WriteLine(proName + "已启动");
}
}
}
catch (Exception e)
{
sb.Append(e.ToString() + "\r\n");
result = false;
//Console.WriteLine(e.ToString());
}
foreach (var proName in pro)
{
Process[] proA = Process.GetProcessesByName(proName);
if (proA.Length > 0)
{
result = true;
}
else
{
result = false;
//Console.WriteLine(proName + "已启动");
}
}
return result;
}
List<string> pro = new List<string> { "Print Spooler" };
if (Start(pro))
{
sb.Append("已启动OK\r\n");
txtInform.Text = sb.ToString();
//Console.WriteLine("已启动OK");
// Console.ReadKey();
}
else
{
txtInform.Text = sb.ToString();
}