Start C# with the UseShellExecute property set.
In C#, you can launch a new process using the Process.Start method and set the UseShellExecute property.
The UseShellExecute property determines whether to use the operating system shell to start a process. By default, this property is set to true, meaning that the shell is used to start the process. Setting it to false means that the shell is not used, and the executable file is run directly.
Below is an example code demonstrating how to set the UseShellExecute property.
using System;
using System.Diagnostics;
class Program
{
static void Main()
{
// 创建一个新的进程实例
Process process = new Process();
// 设置要启动的可执行文件路径
process.StartInfo.FileName = "calc.exe";
// 设置UseShellExecute属性为false
process.StartInfo.UseShellExecute = false;
// 启动进程
process.Start();
// 等待进程退出
process.WaitForExit();
}
}
In the example above, a new process instance is created with the executable file path set to “calc.exe” (Calculator application). The UseShellExecute property is then set to false, indicating that no shell program will be used to start the process. Finally, the process is started by calling the Start method and the WaitForExit method is used to wait for the process to exit.
Please note that if the executable file you want to start requires administrator privileges, you need to set the UseShellExecute property to true in order to use a shell program to start the process, and elevate permissions by setting the Verb property to the desired action (such as “runas”).