ProcessHelp 进程类(启动,杀掉,查找)
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 > 0) { p[0].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 > 0) { return true; } else { return false; } } } }
作者:三小
声明:原创博客请在转载时保留原文链接或者在文章开头加上本人博客地址,如发现错误,欢迎批评指正。凡是转载于本人的文章,不能设置打赏功能,如有特殊需求请与本人联系!