租用问题

质量为本、客户为根、勇于拼搏、务实创新

< 返回租用问题列表

C#中useshellexecute属性如何设置

发布时间:2023-08-03 08:29:16

C#中useshellexecute属性如何设置

在C#中,可以通过Process.StartInfo属性的UseShellExecute属性来设置UseShellExecute属性的值。
UseShellExecute属性是一个布尔值,用于指定是否是使用操作系统的外壳程序来履行命令。默许情况下,UseShellExecute属性的值为true,表示使用外壳程序来履行命令。如果将UseShellExecute属性设置为false,则可使用Process.StartInfo属性的FileName属性来履行指定的可履行文件。
以下是使用UseShellExecute属性的示例代码:
```csharp
using System;
using System.Diagnostics;
class Program
{
static void Main()
{
Process process = new Process();
process.StartInfo.FileName = "notepad.exe";
process.StartInfo.UseShellExecute = false;
process.Start();
}
}
```
在上面的示例中,我们创建了一个新的Process对象,然后将FileName属性设置为"notepad.exe",表示要履行记事本利用程序。接下来,我们将UseShellExecute属性设置为false,表示不使用外壳程序来履行命令。最后,调用Start方法启动进程。
请注意,设置UseShellExecute属性为false时,需要设置StartInfo属性的FileName属性来指定要履行的可履行文件。