c#启动exe 5种方式
时间: 2023-07-15 21:15:01 浏览: 52
在C#中启动一个exe文件有多种方式,以下是其中五种常见的方式:
1. 使用Process.Start()方法启动exe文件。这是最常见的方法,可以在代码中使用以下语句来启动一个exe文件:
```
Process.Start("path/to/exe/file.exe");
```
2. 使用Process类的构造函数创建一个新的进程对象,并设置StartInfo属性来指定exe文件路径和其他启动选项。以下是一个示例代码:
```
Process process = new Process();
process.StartInfo.FileName = "path/to/exe/file.exe";
process.StartInfo.Arguments = "arg1 arg2";
process.Start();
```
3. 使用Shell类的静态方法启动exe文件。以下是一个示例代码:
```
ShellExecute(IntPtr.Zero, "open", "path/to/exe/file.exe", "", "", ShowCommands.SW_SHOWNORMAL);
```
4. 使用WMI(Windows Management Instrumentation)启动exe文件。以下是一个示例代码:
```
ManagementClass processClass = new ManagementClass("Win32_Process");
object[] methodArgs = { "path/to/exe/file.exe" };
processClass.InvokeMethod("Create", methodArgs);
```
5. 使用AppDomain类的ExecuteAssembly方法运行exe文件。以下是一个示例代码:
```
AppDomain.CurrentDomain.ExecuteAssembly("path/to/exe/file.exe");
```
以上是启动exe文件的五种常见方式,可以根据需要选择适合的方法来启动exe文件。