using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text; namespace Share
{
public class ProcessHelp
{
public static bool StartProcess(string filename, params string[] args)
{
try
{
string s = "";
foreach (string arg in args)
{
s = s + arg + " ";
}
s = s.Trim();
Process myprocess = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo(filename, s);
myprocess.StartInfo = startInfo; //通过以下参数可以控制exe的启动方式,具体参照 myprocess.StartInfo.下面的参数,如以无界面方式启动exe等
myprocess.StartInfo.UseShellExecute = false;
myprocess.Start();
return true;
}
catch (Exception ex)
{
LogHelp.WriteLog(ex.Message + ex.StackTrace);
}
return false;
}
/// <summary>
/// 杀掉指定名字的进程
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static bool KillProcess(string name)
{
Process[] p = Process.GetProcessesByName(name);
if (p.Length > )
{
p[].Kill();
return true;
}
else
{
return false;
}
}
/// <summary>
/// 查找是否有指定名字的进程名
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static bool IsProcess(string name)
{
Process[] p = Process.GetProcessesByName(name);
if (p.Length > )
{
return true;
}
else
{
return false;
}
}
}
}