[C#]C# calls the process to open an exe program

Article directory


1. Process

Create a new WinForm program and write code to specify the exe file under the absolute path (or relative path) of the program to be called.
Insert image description here

Calling code:
Here the path of another program I call is:

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

You can change this path to the path of the program you want to call.

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

2. Effect

To run it, click button 1 to call multiple exes at the same time.

Insert image description here

The called exe program runs:

Insert image description here


Summarize

The program that can be called may not be a C# program, but may be other applications , such as some tools that come with Windows, or programs made in other languages. As long as it is an exe, it can start the process.

Guess you like

Origin blog.csdn.net/qq_38628970/article/details/132691792