ProcessStartInfo 类  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
指定启动进程时使用的一组值。
public ref class ProcessStartInfo sealedpublic sealed class ProcessStartInfo[System.ComponentModel.TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))]
public sealed class ProcessStartInfotype ProcessStartInfo = class[<System.ComponentModel.TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))>]
type ProcessStartInfo = classPublic NotInheritable Class ProcessStartInfo- 继承
- 
				ProcessStartInfo
- 属性
示例
下面的代码示例演示如何使用 ProcessStartInfo 类启动 Internet Explorer。 目标 URL 作为 ProcessStartInfo 参数提供。
#using <System.dll>
using namespace System;
using namespace System::Diagnostics;
using namespace System::ComponentModel;
// 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()
{
    // URLs 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 = gcnew ProcessStartInfo("IExplore.exe");
    startInfo->WindowStyle = ProcessWindowStyle::Minimized;
    Process::Start(startInfo);
    startInfo->Arguments = "www.northwindtraders.com";
    Process::Start(startInfo);
}
int main()
{
    // Get the path that stores favorite links.
    String^ myFavoritesPath = Environment::GetFolderPath(Environment::SpecialFolder::Favorites);
    OpenApplication(myFavoritesPath);
    OpenWithArguments();
    OpenWithStartInfo();
}
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();
        }
    }
}
Imports System.Diagnostics
Imports System.ComponentModel
Namespace MyProcessSample
    Class MyProcess
        ' Opens the Internet Explorer application.
        Public Sub OpenApplication(myFavoritesPath As String)
            ' 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)
        End Sub
        ' Opens URLs and .html documents using Internet Explorer.
        Sub OpenWithArguments()
            ' URLs 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")
        End Sub
        ' Uses the ProcessStartInfo class to start new processes,
        ' both in a minimized mode.
        Sub OpenWithStartInfo()
            Dim startInfo As New ProcessStartInfo("IExplore.exe")
            startInfo.WindowStyle = ProcessWindowStyle.Minimized
            Process.Start(startInfo)
            startInfo.Arguments = "www.northwindtraders.com"
            Process.Start(startInfo)
        End Sub
        Shared Sub Main()
            ' Get the path that stores favorite links.
            Dim myFavoritesPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Favorites)
            Dim myProcess As New MyProcess()
            myProcess.OpenApplication(myFavoritesPath)
            myProcess.OpenWithArguments()
            myProcess.OpenWithStartInfo()
        End Sub
    End Class
End Namespace 'MyProcessSample
注解
ProcessStartInfo 与 Process 组件一起使用。 使用 Process 类启动进程时,除了附加到正在运行的进程时可用的进程信息外,还可以访问该信息。
可以使用 ProcessStartInfo 类更好地控制启动的过程。 必须至少手动或使用 构造函数设置 FileName 属性。 文件名是任何应用程序或文档。 此处,文档定义为具有与之关联的打开或默认操作的任何文件类型。 可以使用“ 文件夹选项 ”对话框(可通过操作系统使用)查看计算机的已注册文件类型及其关联的应用程序。 “ 高级 ”按钮将打开一个对话框,显示是否存在与特定已注册文件类型关联的打开操作。
此外,还可以设置其他属性,用于定义要对该文件执行的操作。 可以为属性指定特定于属性Verb类型的FileName值。 例如,可以为文档类型指定“打印”。 此外,还可以将属性值指定 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, IEnumerable<String>) | 指定启动进程时使用的一组值。 | 
| 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 | 获取或设置标准输出的首选编码。 | 
| UseCredentialsForNetworkingOnly | 指定启动进程时使用的一组值。 | 
| UserName | 获取或设置在启动进程时使用的用户名。 如果使用 UPN 格式, | 
| UseShellExecute | 获取或设置指示是否使用操作系统 shell 启动进程的值。 | 
| Verb | 获取或设置打开 FileName 属性指定的应用程序或文档时要使用的谓词。 | 
| Verbs | 获取与 FileName 属性指定的文件类型关联的一组谓词。 | 
| WindowStyle | 获取或设置启动进程时使用的窗口状态。 | 
| WorkingDirectory | 当 UseShellExecute 属性为  | 
方法
| Equals(Object) | 确定指定对象是否等于当前对象。(继承自 Object) | 
| GetHashCode() | 作为默认哈希函数。(继承自 Object) | 
| GetType() | 获取当前实例的 Type。(继承自 Object) | 
| MemberwiseClone() | 创建当前 Object 的浅表副本。(继承自 Object) | 
| ToString() | 返回表示当前对象的字符串。(继承自 Object) |