定义
指定启动进程时使用的一组值。
public sealed class ProcessStartInfo
- 继承
-
ProcessStartInfo
示例
下面的代码示例演示如何使用 ProcessStartInfo 类启动 Internet Explorer,并提供目标 URL 作为 ProcessStartInfo 参数。
using System;
using System.Diagnostics;
using System.ComponentModel;
namespace MyProcessSample
{
class MyProcess
{
// Opens the Internet Explorer application.
void OpenApplication(string myFavoritesPath)
{
// Start Internet Explorer. Defaults to the home page.
Process.Start("IExplore.exe");
// Display the contents of the favorites folder in the browser.
Process.Start(myFavoritesPath);
}
// Opens urls and .html documents using Internet Explorer.
void OpenWithArguments()
{
// url's are not considered documents. They can only be opened
// by passing them as arguments.
Process.Start("IExplore.exe", "www.northwindtraders.com");
// Start a Web page using a browser associated with .html and .asp files.
Process.Start("IExplore.exe", "C:\\myPath\\myFile.htm");
Process.Start("IExplore.exe", "C:\\myPath\\myFile.asp");
}
// Uses the ProcessStartInfo class to start new processes,
// both in a minimized mode.
void OpenWithStartInfo()
{
ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe");
startInfo.WindowStyle = ProcessWindowStyle.Minimized;
Process.Start(startInfo);
startInfo.Arguments = "www.northwindtraders.com";
Process.Start(startInfo);
}
static void Main()
{
// Get the path that stores favorite links.
string myFavoritesPath =
Environment.GetFolderPath(Environment.SpecialFolder.Favorites);
MyProcess myProcess = new MyProcess();
myProcess.OpenApplication(myFavoritesPath);
myProcess.OpenWithArguments();
myProcess.OpenWithStartInfo();
}
}
}
注解
ProcessStartInfo 与 Process 组件一起使用。 使用 Process 类启动进程时,除了附加到正在运行的进程时可用的进程信息外,还可以访问该信息。
可以使用 ProcessStartInfo 类更好地控制启动的过程。 必须至少手动或使用 构造函数设置 FileName 属性。 文件名是任何应用程序或文档。 此处,文档定义为具有与之关联的打开或默认操作的任何文件类型。 可以使用“ 文件夹选项 ”对话框(可通过操作系统使用)查看计算机的已注册文件类型及其关联的应用程序。 “ 高级 ”按钮将打开一个对话框,显示是否存在与特定已注册文件类型关联的打开操作。
此外,还可以设置其他属性,用于定义要对该文件执行的操作。 可以指定特定于属性的属性FileNameVerb类型的值。 例如,可以为文档类型指定“打印”。 此外,还可以将属性值指定 Arguments 为要传递给文件的打开过程的命令行参数。 例如,如果在 属性中 FileName 指定文本编辑器应用程序,则可以使用 Arguments 属性指定要由编辑器打开的文本文件。
标准输入通常是键盘,标准输出和标准错误通常是监视器屏幕。 但是,可以使用 RedirectStandardInput、 RedirectStandardOutput和 RedirectStandardError 属性使进程从文件或其他设备获取输入或返回输出。 如果在组件上使用 StandardInputProcess 、 StandardOutput或 StandardError 属性,则必须先在 属性上ProcessStartInfo设置相应的值。 否则,在读取或写入流时,系统会引发异常。
UseShellExecute设置 属性以指定是否使用操作系统 shell 启动进程。 如果 UseShellExecute 设置为 ,则新进程继承调用进程的标准输入、标准输出和标准错误流,除非 RedirectStandardOutputRedirectStandardInput、 或 RedirectStandardError 属性分别设置为 true。false
可以在进程启动时更改任何 ProcessStartInfo 属性的值。 启动该过程后,更改这些值不起作用。
备注
此类包含在类级别应用于所有成员的链接要求。 SecurityException当直接调用方没有完全信任权限时,将引发 。 有关安全要求的详细信息,请参阅 链接需求。
构造函数
| ProcessStartInfo() |
初始化 ProcessStartInfo 类的新实例,而不指定启动进程时使用的文件名。 |
| ProcessStartInfo(String) |
初始化 ProcessStartInfo 类的新实例,并指定启动进程时使用的诸如应用程序或文档的文件名。 |
| ProcessStartInfo(String, String) |
初始化 ProcessStartInfo 类的新实例,指定启动该进程时使用的应用程序文件名以及要传递给该应用程序的一组命令行自变量。 |
属性
| ArgumentList |
获取启动应用程序时要使用的命令行参数集合。 添加到列表的字符串无需先进行转义。 |
| Arguments |
获取或设置启动应用程序时要使用的一组命令行参数。 |
| CreateNoWindow |
获取或设置指示是否在新窗口中启动该进程的值。 |
| Domain |
获取或设置确定要在启动进程时使用的域的值。 如果此值为 |
| Environment |
获取应用于此进程及其子进程的环境变量。 |
| EnvironmentVariables |
获取文件的搜索路径、临时文件的目录、应用程序特定的选项和其他类似信息。 |
| ErrorDialog |
获取或设置指示不能启动进程时是否向用户显示错误对话框的值。 |
| ErrorDialogParentHandle |
获取或设置在为不能启动的进程显示错误对话框时要使用的窗口句柄。 |
| FileName |
获取或设置要启动的应用程序或文档。 |
| LoadUserProfile |
获取或设置指示是否从注册表加载 Windows 用户配置文件的值。 |
| Password |
获取或设置一个安全字符串,其中包含要在启动进程时使用的用户密码。 |
| PasswordInClearText |
获取或设置明文形式的用户密码以便在启动进程时使用。 |
| RedirectStandardError |
获取或设置指示是否将应用程序的错误输出写入 StandardError 流中的值。 |
| RedirectStandardInput |
获取或设置指示应用程序的输入是否从 StandardInput 流中读取的值。 |
| RedirectStandardOutput |
获取或设置指示是否将应用程序的文本输出写入 StandardOutput 流中的值。 |
| StandardErrorEncoding |
获取或设置错误输出的首选编码。 |
| StandardInputEncoding |
获取或设置标准输入的首选编码。 |
| StandardOutputEncoding |
获取或设置标准输出的首选编码。 |
| UserName |
获取或设置在启动进程时使用的用户名。 如果使用 UPN 格式, |
| UseShellExecute |
获取或设置指示是否使用操作系统 shell 启动进程的值。 |
| Verb |
获取或设置打开 FileName 属性指定的应用程序或文档时要使用的谓词。 |
| Verbs |
获取与 FileName 属性指定的文件类型关联的一组谓词。 |
| WindowStyle |
获取或设置启动进程时使用的窗口状态。 |
| WorkingDirectory |
当 UseShellExecute 属性为 |
方法
| Equals(Object) |
确定指定对象是否等于当前对象。 (继承自 Object) |
| GetHashCode() |
作为默认哈希函数。 (继承自 Object) |
| GetType() |
获取当前实例的 Type。 (继承自 Object) |
| MemberwiseClone() |
创建当前 Object 的浅表副本。 (继承自 Object) |
| ToString() |
返回表示当前对象的字符串。 (继承自 Object) |
适用于
| 产品 | 版本 |
|---|---|
| .NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7 |
| .NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8 |
| .NET Standard | 2.0, 2.1 |
| Xamarin.iOS | 10.8 |
| Xamarin.Mac | 3.0 |
另请参阅
建议的内容
-
ProcessStartInfo.UseShellExecute 属性 (System.Diagnostics)
获取或设置指示是否使用操作系统 shell 启动进程的值。
-
Process 类 (System.Diagnostics)
提供对本地和远程进程的访问权限并使你能够启动和停止本地系统进程。
-
Process.WaitForExit 方法 (System.Diagnostics)
设置等待关联进程退出的时间段,并在该段时间结束前或该进程退出前,阻止当前线程执行。 若要避免妨碍当前线程,请使用 Exited 事件。 有关代码示例,请参阅 StandardError 和 ExitCode 属性参考页。
-
Process.StandardOutput 属性 (System.Diagnostics)
获取用于读取应用程序文本输出的流。
| 本博客Android APP 下载 |
![]() |
| 支持我们就给我们点打赏 |
![]() |
| 支付宝打赏 支付宝扫一扫二维码 |
![]() |
| 微信打赏 微信扫一扫二维码 |
![]() |
如果想下次快速找到我,记得点下面的关注哦!




浙公网安备 33010602011771号