【C#】C#调用进程打开一个exe程序


一、过程

新建WinForm程序,并写入代码,明确要调用的程序的绝对路径(或相对路径)下的exe文件。
在这里插入图片描述

调用代码:
这里我调用的另一个程序的路径是:

F:\WindowsFormsApplication2\WindowsFormsApplication2\bin\Debug\WindowsFormsApplication2.exe

你可以把这个路径改成你自己要调用的程序的路径。

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;

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

        private void button1_Click(object sender, EventArgs e)
        {
    
    
            if (System.IO.File.Exists(@"F:\WindowsFormsApplication2\WindowsFormsApplication2\bin\Debug\WindowsFormsApplication2.exe"))
            {
    
    
                System.Diagnostics.Process.Start(@"F:\WindowsFormsApplication2\WindowsFormsApplication2\bin\Debug\WindowsFormsApplication2.exe");    
            }
        }
    }
}

二、效果

运行起来,点击按钮1,也可以同时调用多个exe

在这里插入图片描述

调用的exe程序运行起来:

在这里插入图片描述


总结

可以调用的程序可以不是C#程序,可以是其他应用程序,例如windows自带的一些工具,或者其他语言做的程序,只要是exe都可以启动进程。

猜你喜欢

转载自blog.csdn.net/qq_38628970/article/details/132691792