C# Process 进程管理

1、获取当前系统正在运行的进程

            //获取当前系所有正在运行的进程
            Process[] proc = Process.GetProcesses();
            foreach (Process var in proc)
            {
                textBox1.Text += var+"\n";
                //var.Kill();  杀死本进程
            }

2、进程打开应用程序

private void button2_Click(object sender, EventArgs e)
        {
            //进程打开应用程序  
             Process.Start("notepad");
            //文件默认程序 打开文件
             Process.Start(@"C:\Users\Dell\Desktop\tp.jpg");
            //进程打开文件
             Process proc = new Process();
             //proc.StartInfo.FileName=@"C:\Users\Dell\Desktop\SQLAnalyse.exe";
             //proc.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
             //proc.Start();

             proc.StartInfo.FileName = @"F:\学习实例\设置启动参数\设置启动参数\bin\Debug\设置启动参数.exe";
             //设置启动时窗体状体
             //proc.StartInfo.WindowStyle = ProcessWindowStyle.Minimized; 
             //proc.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
             //打开进程且窗体隐藏
             //proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
             //启动参数
             proc.StartInfo.Arguments = "2";
             proc.Start();

        }

设置程序启动参数

  static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main(string[] age)
        {

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            int f = age.Length;
            if (age[0] == "1")
            {
                Form1 from = new Form1();
                from.Text = "页面"+age[0];
                Application.Run(from);
            }
            if (age[0] == "2")
            {
                Form1 from = new Form1();
                from.Text = "页面"+age[0];
                Application.Run(from);
            }
            
           
        }
    }

猜你喜欢

转载自www.cnblogs.com/apimeng/p/9553448.html
今日推荐