2 // System.Diagnostics.ProcessStartInfo.cs
5 // Dick Porter (dick@ximian.com)
6 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
8 // (C) 2002 Ximian, Inc. http://www.ximian.com
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using Microsoft
.Win32
;
33 using System
.Collections
;
34 using System
.Collections
.Specialized
;
35 using System
.ComponentModel
;
37 using System
.Security
;
38 using System
.Security
.Permissions
;
41 namespace System
.Diagnostics
43 [TypeConverter (typeof (ExpandableObjectConverter
))]
44 [PermissionSet (SecurityAction
.LinkDemand
, Unrestricted
= true)]
45 public sealed class ProcessStartInfo
47 /* keep these fields in this order and in sync with metadata/process.h */
48 private string arguments
= "";
49 private IntPtr error_dialog_parent_handle
= (IntPtr
)0;
50 private string filename
= "";
51 private string verb
= "";
52 private string working_directory
= "";
53 private ProcessStringDictionary envVars
;
54 private bool create_no_window
= false;
55 private bool error_dialog
= false;
56 private bool redirect_standard_error
= false;
57 private bool redirect_standard_input
= false;
58 private bool redirect_standard_output
= false;
59 private bool use_shell_execute
= true;
60 private ProcessWindowStyle window_style
= ProcessWindowStyle
.Normal
;
61 private Encoding encoding_stderr
, encoding_stdout
;
62 private string username
, domain
;
64 private SecureString password
;
66 private object password
; // dummy
68 private bool load_user_profile
;
70 public ProcessStartInfo()
74 public ProcessStartInfo(string filename
)
76 this.filename
= filename
;
79 public ProcessStartInfo(string filename
, string arguments
)
81 this.filename
= filename
;
82 this.arguments
= arguments
;
85 [RecommendedAsConfigurable (true), DefaultValue ("")]
86 [TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts
.AssemblySystem_Design
)]
88 [MonitoringDescription ("Command line agruments for this process.")]
90 [NotifyParentPropertyAttribute (true)]
92 public string Arguments
{
101 [DefaultValue (false)]
102 [MonitoringDescription ("Start this process with a new window.")]
104 [NotifyParentPropertyAttribute (true)]
106 public bool CreateNoWindow
{
108 return(create_no_window
);
111 create_no_window
= value;
115 [DesignerSerializationVisibility (DesignerSerializationVisibility
.Content
), DefaultValue (null)]
116 [Editor ("System.Diagnostics.Design.StringDictionaryEditor, " + Consts
.AssemblySystem_Design
, "System.Drawing.Design.UITypeEditor, " + Consts
.AssemblySystem_Drawing
)]
117 [MonitoringDescription ("Environment variables used for this process.")]
119 [NotifyParentPropertyAttribute (true)]
121 public StringDictionary EnvironmentVariables
{
123 if (envVars
== null) {
124 envVars
= new ProcessStringDictionary ();
125 foreach (DictionaryEntry entry
in Environment
.GetEnvironmentVariables ())
126 envVars
.Add ((string) entry
.Key
, (string) entry
.Value
);
133 internal bool HaveEnvVars
{
134 get { return (envVars != null); }
137 [DefaultValue (false)]
138 [MonitoringDescription ("Thread shows dialogboxes for errors.")]
140 [NotifyParentPropertyAttribute (true)]
142 public bool ErrorDialog
{
144 return(error_dialog
);
147 error_dialog
= value;
151 [DesignerSerializationVisibility (DesignerSerializationVisibility
.Hidden
), Browsable (false)]
152 public IntPtr ErrorDialogParentHandle
{
154 return(error_dialog_parent_handle
);
157 error_dialog_parent_handle
= value;
161 [RecommendedAsConfigurable (true), DefaultValue ("")]
162 [Editor ("System.Diagnostics.Design.StartFileNameEditor, " + Consts
.AssemblySystem_Design
, "System.Drawing.Design.UITypeEditor, " + Consts
.AssemblySystem_Drawing
)]
163 [TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts
.AssemblySystem_Design
)]
164 [MonitoringDescription ("The name of the resource to start this process.")]
166 [NotifyParentPropertyAttribute (true)]
168 public string FileName
{
177 [DefaultValue (false)]
178 [MonitoringDescription ("Errors of this process are redirected.")]
180 [NotifyParentPropertyAttribute (true)]
182 public bool RedirectStandardError
{
184 return(redirect_standard_error
);
187 redirect_standard_error
= value;
191 [DefaultValue (false)]
192 [MonitoringDescription ("Standard input of this process is redirected.")]
194 [NotifyParentPropertyAttribute (true)]
196 public bool RedirectStandardInput
{
198 return(redirect_standard_input
);
201 redirect_standard_input
= value;
205 [DefaultValue (false)]
206 [MonitoringDescription ("Standart output of this process is redirected.")]
208 [NotifyParentPropertyAttribute (true)]
210 public bool RedirectStandardOutput
{
212 return(redirect_standard_output
);
215 redirect_standard_output
= value;
220 public Encoding StandardErrorEncoding
{
221 get { return encoding_stderr; }
222 set { encoding_stderr = value; }
225 public Encoding StandardOutputEncoding
{
226 get { return encoding_stdout; }
227 set { encoding_stdout = value; }
231 [DefaultValue (true)]
232 [MonitoringDescription ("Use the shell to start this process.")]
234 [NotifyParentPropertyAttribute (true)]
236 public bool UseShellExecute
{
238 return(use_shell_execute
);
241 use_shell_execute
= value;
246 [TypeConverter ("System.Diagnostics.Design.VerbConverter, " + Consts
.AssemblySystem_Design
)]
247 [MonitoringDescription ("The verb to apply to a used document.")]
249 [NotifyParentPropertyAttribute (true)]
260 static readonly string [] empty
= new string [0];
262 [DesignerSerializationVisibility (DesignerSerializationVisibility
.Hidden
), Browsable (false)]
263 public string[] Verbs
{
265 string ext
= filename
== null | filename
.Length
== 0 ?
266 null : Path
.GetExtension (filename
);
274 switch (Environment
.OSVersion
.Platform
) {
277 case (PlatformID
)128:
278 return empty
; // no verb on non-Windows
280 RegistryKey rk
= null, rk2
= null, rk3
= null;
282 rk
= Registry
.ClassesRoot
.OpenSubKey (ext
);
283 string k
= rk
!= null ? rk
.GetValue (null) as string : null;
284 rk2
= k
!= null ? Registry
.ClassesRoot
.OpenSubKey (k
) : null;
285 rk3
= rk2
!= null ? rk2
.OpenSubKey ("shell") : null;
286 return rk3
!= null ? rk3
.GetSubKeyNames () : null;
300 [DefaultValue (typeof (ProcessWindowStyle
), "Normal")]
301 [MonitoringDescription ("The window style used to start this process.")]
303 [NotifyParentPropertyAttribute (true)]
305 public ProcessWindowStyle WindowStyle
{
307 return(window_style
);
310 window_style
= value;
314 [RecommendedAsConfigurable (true), DefaultValue ("")]
315 [Editor ("System.Diagnostics.Design.WorkingDirectoryEditor, " + Consts
.AssemblySystem_Design
, "System.Drawing.Design.UITypeEditor, " + Consts
.AssemblySystem_Drawing
)]
316 [TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts
.AssemblySystem_Design
)]
317 [MonitoringDescription ("The initial directory for this process.")]
319 [NotifyParentPropertyAttribute (true)]
321 public string WorkingDirectory
{
323 return(working_directory
);
326 working_directory
= value == null ? String
.Empty
: value;
331 [NotifyParentPropertyAttribute (true)]
332 public bool LoadUserProfile
{
333 get { return load_user_profile; }
334 set { load_user_profile = value; }
337 [NotifyParentPropertyAttribute (true)]
338 public string UserName
{
339 get { return username; }
340 set { username = value; }
343 [NotifyParentPropertyAttribute (true)]
344 public string Domain
{
345 get { return domain; }
346 set { domain = value; }
349 public SecureString Password
{
350 get { return password; }
351 set { password = value; }