The Labs \ Source Viewer \ SSCLI \ System.Diagnostics \ ProcessStartInfo

  1. //------------------------------------------------------------------------------
  2. // <copyright file="ProcessStartInfo.cs" company="Microsoft">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. namespace System.Diagnostics
  16. {
  17.     using System.Threading;
  18.     using System.Runtime.InteropServices;
  19.     using System.ComponentModel;
  20.     using System.Diagnostics;
  21.     using System;
  22.     using System.Security;
  23.     using System.Security.Permissions;
  24.     using Microsoft.Win32;
  25.     using System.IO;
  26.     using System.ComponentModel.Design;
  27.     using System.Collections.Specialized;
  28.     using System.Collections;
  29.     using System.Globalization;
  30.     using System.Text;
  31.    
  32.     /// <devdoc>
  33.     /// A set of values used to specify a process to start. This is
  34.     /// used in conjunction with the <see cref='System.Diagnostics.Process'/>
  35.     /// component.
  36.     /// </devdoc>
  37.    
  38.         // Disabling partial trust scenarios
  39.     [TypeConverter(typeof(ExpandableObjectConverter)), PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust"), HostProtection(SharedState = true, SelfAffectingProcessMgmt = true)]
  40.     public sealed class ProcessStartInfo
  41.     {
  42.         string fileName;
  43.         string arguments;
  44.         string directory;
  45.         string verb;
  46.         ProcessWindowStyle windowStyle;
  47.         bool errorDialog;
  48.         IntPtr errorDialogParentHandle;
  49.         bool useShellExecute = false;
  50.         bool redirectStandardInput = false;
  51.         bool redirectStandardOutput = false;
  52.         bool redirectStandardError = false;
  53.         Encoding standardOutputEncoding;
  54.         Encoding standardErrorEncoding;
  55.        
  56.         bool createNoWindow = false;
  57.         WeakReference weakParentProcess;
  58.         internal StringDictionary environmentVariables;
  59.        
  60.         /// <devdoc>
  61.         /// Default constructor. At least the <see cref='System.Diagnostics.ProcessStartInfo.FileName'/>
  62.         /// property must be set before starting the process.
  63.         /// </devdoc>
  64.         public ProcessStartInfo()
  65.         {
  66.         }
  67.        
  68.         internal ProcessStartInfo(Process parent)
  69.         {
  70.             this.weakParentProcess = new WeakReference(parent);
  71.         }
  72.        
  73.         /// <devdoc>
  74.         /// Specifies the name of the application or document that is to be started.
  75.         /// </devdoc>
  76.         public ProcessStartInfo(string fileName)
  77.         {
  78.             this.fileName = fileName;
  79.         }
  80.        
  81.         /// <devdoc>
  82.         /// Specifies the name of the application that is to be started, as well as a set
  83.         /// of command line arguments to pass to the application.
  84.         /// </devdoc>
  85.         public ProcessStartInfo(string fileName, string arguments)
  86.         {
  87.             this.fileName = fileName;
  88.             this.arguments = arguments;
  89.         }
  90.        
  91.         /// <devdoc>
  92.         /// <para>
  93.         /// Specifies the verb to use when opening the filename. For example, the "print"
  94.         /// verb will print a document specified using <see cref='System.Diagnostics.ProcessStartInfo.FileName'/>.
  95.         /// Each file extension has it's own set of verbs, which can be obtained using the
  96.         /// <see cref='System.Diagnostics.ProcessStartInfo.Verbs'/> property.
  97.         /// The default verb can be specified using "".
  98.         /// </para>
  99.         /// <note type="rnotes">
  100.         /// Discuss 'opening' vs. 'starting.' I think the part about the
  101.         /// default verb was a dev comment.
  102.         /// Find out what
  103.         /// that means.
  104.         /// </note>
  105.         /// </devdoc>
  106.         [DefaultValueAttribute(""), TypeConverter("System.Diagnostics.Design.VerbConverter, " + AssemblyRef.SystemDesign), MonitoringDescription(SR.ProcessVerb), NotifyParentProperty(true)]
  107.         public string Verb {
  108.             get {
  109.                 if (verb == null)
  110.                     return string.Empty;
  111.                 return verb;
  112.             }
  113.             set { verb = value; }
  114.         }
  115.        
  116.         /// <devdoc>
  117.         /// Specifies the set of command line arguments to use when starting the application.
  118.         /// </devdoc>
  119.         [DefaultValueAttribute(""), MonitoringDescription(SR.ProcessArguments), RecommendedAsConfigurable(true), TypeConverter("System.Diagnostics.Design.StringValueConverter, " + AssemblyRef.SystemDesign), NotifyParentProperty(true)]
  120.         public string Arguments {
  121.             get {
  122.                 if (arguments == null)
  123.                     return string.Empty;
  124.                 return arguments;
  125.             }
  126.             set { arguments = value; }
  127.         }
  128.        
  129.         /// <devdoc>
  130.         /// <para>[To be supplied.]</para>
  131.         /// </devdoc>
  132.         [DefaultValue(false), MonitoringDescription(SR.ProcessCreateNoWindow), NotifyParentProperty(true)]
  133.         public bool CreateNoWindow {
  134.             get { return createNoWindow; }
  135.             set { createNoWindow = value; }
  136.         }
  137.        
  138.         /// <devdoc>
  139.         /// <para>[To be supplied.]</para>
  140.         /// </devdoc>
  141.         [Editor("System.Diagnostics.Design.StringDictionaryEditor, " + AssemblyRef.SystemDesign, "System.Drawing.Design.UITypeEditor, " + AssemblyRef.SystemDrawing), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), DefaultValue(null), MonitoringDescription(SR.ProcessEnvironmentVariables), NotifyParentProperty(true)]
  142.         public StringDictionary EnvironmentVariables {
  143.             get {
  144.                 if (environmentVariables == null) {
  145.                     #if PLATFORM_UNIX
  146.                     environmentVariables = new CaseSensitiveStringDictionary();
  147.                     #else
  148.                     environmentVariables = new StringDictionary();
  149.                     #endif // PLATFORM_UNIX
  150.                    
  151.                     // if not in design mode, initialize the child environment block with all the parent variables
  152.                     if (!(this.weakParentProcess != null && this.weakParentProcess.IsAlive && ((Component)this.weakParentProcess.Target).Site != null && ((Component)this.weakParentProcess.Target).Site.DesignMode)) {
  153.                        
  154.                         foreach (DictionaryEntry entry in Environment.GetEnvironmentVariables())
  155.                             environmentVariables.Add((string)entry.Key, (string)entry.Value);
  156.                     }
  157.                    
  158.                 }
  159.                 return environmentVariables;
  160.             }
  161.         }
  162.        
  163.         /// <devdoc>
  164.         /// <para>[To be supplied.]</para>
  165.         /// </devdoc>
  166.         [DefaultValue(false), MonitoringDescription(SR.ProcessRedirectStandardInput), NotifyParentProperty(true)]
  167.         public bool RedirectStandardInput {
  168.             get { return redirectStandardInput; }
  169.             set { redirectStandardInput = value; }
  170.         }
  171.        
  172.         /// <devdoc>
  173.         /// <para>[To be supplied.]</para>
  174.         /// </devdoc>
  175.         [DefaultValue(false), MonitoringDescription(SR.ProcessRedirectStandardOutput), NotifyParentProperty(true)]
  176.         public bool RedirectStandardOutput {
  177.             get { return redirectStandardOutput; }
  178.             set { redirectStandardOutput = value; }
  179.         }
  180.        
  181.         /// <devdoc>
  182.         /// <para>[To be supplied.]</para>
  183.         /// </devdoc>
  184.         [DefaultValue(false), MonitoringDescription(SR.ProcessRedirectStandardError), NotifyParentProperty(true)]
  185.         public bool RedirectStandardError {
  186.             get { return redirectStandardError; }
  187.             set { redirectStandardError = value; }
  188.         }
  189.        
  190.        
  191.         public Encoding StandardErrorEncoding {
  192.             get { return standardErrorEncoding; }
  193.             set { standardErrorEncoding = value; }
  194.         }
  195.        
  196.         public Encoding StandardOutputEncoding {
  197.             get { return standardOutputEncoding; }
  198.             set { standardOutputEncoding = value; }
  199.         }
  200.        
  201.        
  202.         /// <devdoc>
  203.         /// <para>[To be supplied.]</para>
  204.         /// </devdoc>
  205.         [DefaultValue(true), MonitoringDescription(SR.ProcessUseShellExecute), NotifyParentProperty(true)]
  206.         public bool UseShellExecute {
  207.             get { return useShellExecute; }
  208.             set { useShellExecute = value; }
  209.         }
  210.        
  211.        
  212.         /// <devdoc>
  213.         /// <para>
  214.         /// Returns or sets the application, document, or URL that is to be launched.
  215.         /// </para>
  216.         /// </devdoc>
  217.         [DefaultValue(""), Editor("System.Diagnostics.Design.StartFileNameEditor, " + AssemblyRef.SystemDesign, "System.Drawing.Design.UITypeEditor, " + AssemblyRef.SystemDrawing), MonitoringDescription(SR.ProcessFileName), RecommendedAsConfigurable(true), TypeConverter("System.Diagnostics.Design.StringValueConverter, " + AssemblyRef.SystemDesign), NotifyParentProperty(true)]
  218.         public string FileName {
  219.             get {
  220.                 if (fileName == null)
  221.                     return string.Empty;
  222.                 return fileName;
  223.             }
  224.             set { fileName = value; }
  225.         }
  226.        
  227.         /// <devdoc>
  228.         /// Returns or sets the initial directory for the process that is started.
  229.         /// Specify "" to if the default is desired.
  230.         /// </devdoc>
  231.         [DefaultValue(""), MonitoringDescription(SR.ProcessWorkingDirectory), Editor("System.Diagnostics.Design.WorkingDirectoryEditor, " + AssemblyRef.SystemDesign, "System.Drawing.Design.UITypeEditor, " + AssemblyRef.SystemDrawing), RecommendedAsConfigurable(true), TypeConverter("System.Diagnostics.Design.StringValueConverter, " + AssemblyRef.SystemDesign), NotifyParentProperty(true)]
  232.         public string WorkingDirectory {
  233.             get {
  234.                 if (directory == null)
  235.                     return string.Empty;
  236.                 return directory;
  237.             }
  238.             set { directory = value; }
  239.         }
  240.        
  241.         /// <devdoc>
  242.         /// Sets or returns whether or not an error dialog should be displayed to the user
  243.         /// if the process can not be started.
  244.         /// </devdoc>
  245.         [DefaultValueAttribute(false), MonitoringDescription(SR.ProcessErrorDialog), NotifyParentProperty(true)]
  246.         public bool ErrorDialog {
  247.             get { return errorDialog; }
  248.             set { errorDialog = value; }
  249.         }
  250.        
  251.         /// <devdoc>
  252.         /// Sets or returns the window handle to use for the error dialog that is shown
  253.         /// when a process can not be started. If <see cref='System.Diagnostics.ProcessStartInfo.ErrorDialog'/>
  254.         /// is true, this specifies the parent window for the dialog that is shown. It is
  255.         /// useful to specify a parent in order to keep the dialog in front of the application.
  256.         /// </devdoc>
  257.         [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  258.         public IntPtr ErrorDialogParentHandle {
  259.             get { return errorDialogParentHandle; }
  260.             set { errorDialogParentHandle = value; }
  261.         }
  262.        
  263.         /// <devdoc>
  264.         /// Sets or returns the style of window that should be used for the newly created process.
  265.         /// </devdoc>
  266.         [DefaultValueAttribute(System.Diagnostics.ProcessWindowStyle.Normal), MonitoringDescription(SR.ProcessWindowStyle), NotifyParentProperty(true)]
  267.         public ProcessWindowStyle WindowStyle {
  268.             get { return windowStyle; }
  269.             set {
  270.                 if (!Enum.IsDefined(typeof(ProcessWindowStyle), value))
  271.                     throw new InvalidEnumArgumentException("value", (int)value, typeof(ProcessWindowStyle));
  272.                
  273.                 windowStyle = value;
  274.             }
  275.         }
  276.     }
  277. }

Developer Fusion