首页 > 代码库 > 2017-5-4 进程

2017-5-4 进程

进程:
一个应用程序就是一个进程
开启某个进程
Process.Start("文件缩写名");
通过绝对路径开启某个进程
Process p = new Process();
p.StartInfo = new ProcessStartInfo("要打开的程序绝对路径");
p.Start();

获取全部开启的进程:
Process.GetProcesses();

杀死进程
对象.Kill();

常用的开启网页注册账号:
Process.Start("http://.....");

例如:

技术分享

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication7
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //Process.Start("calc");
            //Process.Start("notepad");
            //Process.Start("chrome");
            Process pro = new Process();
            ProcessStartInfo psi = new ProcessStartInfo(textBox1.Text);
            pro.StartInfo = psi;
            pro.Start();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "应用程序|*.exe";
          DialogResult dr= openFileDialog1.ShowDialog();
            if(dr==DialogResult.OK)
            {
                textBox1.Text = openFileDialog1.FileName;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {

        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Process.Start("http://www.qq.com");
        }

        private void button3_Click_1(object sender, EventArgs e)
        {
          Process[] proc=  Process.GetProcesses();
            foreach(Process p in proc)
            {
                //p.Kill();
                richTextBox1.Text += p.ToString() + "/r";
            }
        }
    }
}

 

2017-5-4 进程