ProcessStartInfo 类

指定启动进程时使用的一组值。

**命名空间:**System.Diagnostics
**程序集:**System(在 system.dll 中)

语法

声明
Public NotInheritable Class ProcessStartInfo
用法
Dim instance As ProcessStartInfo
public sealed class ProcessStartInfo
public ref class ProcessStartInfo sealed
public final class ProcessStartInfo
public final class ProcessStartInfo

备注

提示

应用于此类的 HostProtectionAttribute 属性 (attribute) 具有以下 Resources 属性 (property) 值:SharedState | SelfAffectingProcessMgmtHostProtectionAttribute 不影响桌面应用程序(这些应用程序通常通过双击图标、键入命令或在浏览器中输入 URL 来启动)。有关更多信息,请参见 HostProtectionAttribute 类或 SQL Server 编程和宿主保护属性

ProcessStartInfoProcess 组件一起使用。使用 Process 类启动进程时,您还可以访问附加到当前运行进程时可用的进程信息之外的进程信息。

可以使用 ProcessStartInfo 类来更好地控制您启动的进程。至少必须以手动方式或使用构造函数来设置 FileName 属性。文件名是任何应用程序或文档。此处,将文档定义为具有与其关联的打开或默认操作的任何文件类型。您可以通过操作系统的“文件夹选项”对话框来查看计算机的已注册文件类型及其关联应用程序。单击“高级”按钮可打开一个对话框,该对话框显示是否存在与特定的注册文件类型相关联的打开操作。

另外,还可以设置定义要对该文件执行的操作的其他属性。可以为 Verb 属性指定特定于 FileName 属性的类型的值。例如,可以为文档类型指定“print”。另外,还可以指定 Arguments 属性值,这些值将成为传递给文件的打开过程的命令行参数。例如,如果在 FileName 属性中指定一个文本编辑器应用程序,则可以使用 Arguments 属性指定将用该编辑器打开的一个文本文件。

标准输入方式通常为键盘,标准输出和标准错误通常显示在监视器屏幕上。但是,可以使用 RedirectStandardInputRedirectStandardOutputRedirectStandardError 属性使进程从文件或其他设备获取输入,或者向文件或其他设备返回输出。如果使用 Process 组件上的 StandardInputStandardOutputStandardError 属性,则必须首先在 ProcessStartInfo 属性上设置相应的值。否则,从流读取或向流写入时,系统会引发异常。

设置 UseShellExecute 以指定是否使用操作系统外壳程序启动进程。

可以更改任何 ProcessStartInfo 属性的值,直到进程启动为止。启动进程后,更改这些值没有效果。

提示

此类在类级别上包含一个链接要求,该要求适用于所有成员。如果直接调用方不具有完全信任权限,则会引发 SecurityException。有关安全要求的详细信息,请参见 链接要求

示例

Imports System
Imports System.Diagnostics
Imports System.ComponentModel


Namespace MyProcessSample
    _
   '/ <summary>
   '/ Shell for the sample.
   '/ </summary>
   Class MyProcess 
      '/ <summary>
      '/ Opens the Internet Explorer application.
      '/ </summary>
      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 'OpenApplication
       
      
      '/ <summary>
      '/ Opens urls and .html documents using Internet Explorer.
      '/ </summary>
      Sub 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")
      End Sub 'OpenWithArguments
      
      
      '/ <summary>
      '/ Uses the ProcessStartInfo class to start new processes, both in a minimized 
      '/ mode.
      '/ </summary>
      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 'OpenWithStartInfo
       
      
      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 'Main 
   End Class 'MyProcess
End Namespace 'MyProcessSample
using System;
using System.Diagnostics;
using System.ComponentModel;

namespace MyProcessSample
{
    /// <summary>
    /// Shell for the sample.
    /// </summary>
    class MyProcess
    {
       
        /// <summary>
        /// Opens the Internet Explorer application.
        /// </summary>
        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);
 
        }
        
        /// <summary>
        /// Opens urls and .html documents using Internet Explorer.
        /// </summary>
        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");
        }
        
        /// <summary>
        /// Uses the ProcessStartInfo class to start new processes, both in a minimized 
        /// mode.
        /// </summary>
        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();

            }   
    }
}
#using <System.dll>

using namespace System;
using namespace System::Diagnostics;
using namespace System::ComponentModel;

/// <summary>
/// Opens the Internet Explorer application.
/// </summary>
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 );
}


/// <summary>
/// Opens urls and .html documents using Internet Explorer.
/// </summary>
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" );
}


/// <summary>
/// Uses the ProcessStartInfo class to start new processes, both in a minimized 
/// mode.
/// </summary>
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();
}

.NET Framework 安全性

继承层次结构

System.Object
  System.Diagnostics.ProcessStartInfo

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0

请参见

参考

ProcessStartInfo 成员
System.Diagnostics 命名空间
Process 类