c#打开关闭进程

        private const string FileName = "test.exe";
        //进程名称不带扩展名
        private const string ProcessName = "test";

        /// <summary>
        /// 打开进程
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public static void Open()
        {
            try
            {
                Process.Start(string.Format(@"{0}\{1}", Application.StartupPath, FileName));
            }
            catch (Exception ex)
            {
            }
        }

        /// <summary>
        /// 关闭进程
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public static void Close()
        {
            try
            {
                //可能存在进程名相同的进程
                foreach (Process process in Process.GetProcessesByName(ProcessName))
                    process.Kill();
            }
            catch (Exception ex)
            {
            }
        }

  

posted @ 2018-12-07 15:05  翻白眼的哈士奇  阅读(2554)  评论(0编辑  收藏  举报