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);
            }
            
           
        }
    }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM