zoukankan      html  css  js  c++  java
  • 练习:WinForm 进程(创建、注销)

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

  • 相关阅读:
    spring data jpa 动态查询(mysql)
    C#面向对象15 多态
    Visual Studio 2012网站如何只生成一个DLL文件
    C#面向对象14 List泛型集合/装箱和拆箱/字典集合(Dictionary)
    C#面向对象13 文件类操作 Path/File/FileStream
    C#面向对象12 集合
    C#面向对象11 里氏转换
    C#面向对象10 继承
    C#面向对象9 字符串
    C# 面向对象8 值类型和引用类型
  • 原文地址:https://www.cnblogs.com/xiao55/p/5839528.html
Copyright © 2011-2022 走看看