using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
namespace 进程
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//创建进程:
private void button1_Click(object sender, EventArgs e)
{
//设置打开文件的类型
openFileDialog1.Filter = "应用程序|*.exe";
//显示对话框并判断用户有没有选中文件
if (openFileDialog1.ShowDialog()==DialogResult.OK)
{
//获取用户选择的文件路径
string path = openFileDialog1.FileName;
//创建进程对象
Process p = new Process();
//创建启动信息对象
ProcessStartInfo psi = new ProcessStartInfo(path);
//设置进程启动信息
p.StartInfo = psi;
//启动进程
p.Start();
//结束进程
//p.Kill();
}
}
//注销进程:
private void button3_Click(object sender, EventArgs e)
{
//1、打开该程序
//获取该程序文件的路径
//string path = Application.StartupPath;(程序的绝对路径:没有最后名称和文件类型)
string path = System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName;
//创建进程对象
Process p = new Process();
//创建启动信息对象
ProcessStartInfo psi = new ProcessStartInfo(path);
//设置启动信息
p.StartInfo = psi;
//启动进程
p.Start();
//2、关闭该程序
this.Close();
}
}
}
![]()
![]()
![]()
![]()