• 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;
                }
            }
        }
    }
  • 相关阅读:
    Uploadify v3.2.1 上传图片并预览
    mybatis批量操作
    500 拦截错误输出
    jsnop
    java目录
    设置360调用样式 IE调用样式
    Spring加载resource时classpath*:与classpath:的区别
    context:annotation-config 与context:component-scan
    Andriod调用http请求
    JDK环境变量
  • 原文地址:https://www.cnblogs.com/lsgsanxiao/p/9020273.html
Copyright © 2020-2023  润新知