SoFunction
Updated on 2025-03-06

C# uses Process class to call external exe programs

When writing programs, you often use the situation of calling executable programs. This article will briefly introduce the method of calling exe in C#. In C#, process operations are performed through the Process class. The Process class is in the package.

Example 1

Copy the codeThe code is as follows:
using ;
Process p = ("");
();//Critical, wait for the external program to exit before it can be executed downward

Through the above code, you can call the Notepad program. Note that if you do not call the system program, you need to enter the full path.

Example 2

When you need to call the cmd program, using the above calling method will pop up an annoying black window. If you want to eliminate it, you need to make a more detailed setup.

The StartInfo property of the Process class contains some process startup information, among which the more important ones are

FileName
Arguments
CreateNoWindow     Is it necessary to create a window
UseShellExecute      Is it necessary to call the system shell program

The above parameters can make the annoying black screen disappear

Copy the codeThe code is as follows:
exep = new ();
= binStr;
= cmdStr;
= true;
= false;
();
();//Critical, wait for the external program to exit before it can be executed downward

or

Copy the codeThe code is as follows:
exep = new ();
startInfo = new ();
= binStr;
= cmdStr;
= true;
= false;
(startInfo);
();//Critical, wait for the external program to exit before it can be executed downward