Linux 拨号vps windows公众号手机端

C#中useshellexecute属性怎么设置

lewis 7年前 (2019-02-05) 阅读数 12 #程序编程

在C#中,可以通过Process.StartInfo属性的UseShellExecute属性来设置UseShellExecute属性的值。

UseShellExecute属性是一个布尔值,用于指定是否使用操作系统的外壳程序来执行命令。默认情况下,UseShellExecute属性的值为true,表示使用外壳程序来执行命令。如果将UseShellExecute属性设置为false,则可以使用Process.StartInfo属性的FileName属性来执行指定的可执行文件。

以下是使用UseShellExecute属性的示例代码:

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属性来指定要执行的可执行文件。

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门