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;
40 using System.Runtime.InteropServices;
42 namespace System.Diagnostics
44 [TypeConverter (typeof (ExpandableObjectConverter))]
45 [PermissionSet (SecurityAction.LinkDemand, Unrestricted = true)]
46 [StructLayout (LayoutKind.Sequential)]
47 public sealed class ProcessStartInfo
49 /* keep these fields in this order and in sync with metadata/process.h */
50 private string arguments = "";
51 private IntPtr error_dialog_parent_handle = (IntPtr)0;
52 private string filename = "";
53 private string verb = "";
54 private string working_directory = "";
55 private ProcessStringDictionary envVars;
56 private bool create_no_window = false;
57 private bool error_dialog = false;
58 private bool redirect_standard_error = false;
59 private bool redirect_standard_input = false;
60 private bool redirect_standard_output = false;
61 private bool use_shell_execute = true;
62 private ProcessWindowStyle window_style = ProcessWindowStyle.Normal;
63 private Encoding encoding_stderr, encoding_stdout;
64 private string username, domain;
65 private SecureString password;
66 private bool load_user_profile;
68 public ProcessStartInfo()
72 public ProcessStartInfo(string filename)
74 this.filename = filename;
77 public ProcessStartInfo(string filename, string arguments)
79 this.filename = filename;
80 this.arguments = arguments;
83 [RecommendedAsConfigurable (true), DefaultValue ("")]
84 [TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts.AssemblySystem_Design)]
86 [MonitoringDescription ("Command line agruments for this process.")]
87 [NotifyParentPropertyAttribute (true)]
88 public string Arguments {
97 [DefaultValue (false)]
98 [MonitoringDescription ("Start this process with a new window.")]
99 [NotifyParentPropertyAttribute (true)]
100 public bool CreateNoWindow {
102 return(create_no_window);
105 create_no_window = value;
109 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content), DefaultValue (null)]
110 [Editor ("System.Diagnostics.Design.StringDictionaryEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
111 [MonitoringDescription ("Environment variables used for this process.")]
112 [NotifyParentPropertyAttribute (true)]
113 public StringDictionary EnvironmentVariables {
115 if (envVars == null) {
116 envVars = new ProcessStringDictionary ();
117 foreach (DictionaryEntry entry in Environment.GetEnvironmentVariables ())
118 envVars.Add ((string) entry.Key, (string) entry.Value);
125 internal bool HaveEnvVars {
126 get { return (envVars != null); }
129 [DefaultValue (false)]
130 [MonitoringDescription ("Thread shows dialogboxes for errors.")]
131 [NotifyParentPropertyAttribute (true)]
132 public bool ErrorDialog {
134 return(error_dialog);
137 error_dialog = value;
141 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden), Browsable (false)]
142 public IntPtr ErrorDialogParentHandle {
144 return(error_dialog_parent_handle);
147 error_dialog_parent_handle = value;
151 [RecommendedAsConfigurable (true), DefaultValue ("")]
152 [Editor ("System.Diagnostics.Design.StartFileNameEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
153 [TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts.AssemblySystem_Design)]
154 [MonitoringDescription ("The name of the resource to start this process.")]
155 [NotifyParentPropertyAttribute (true)]
156 public string FileName {
165 [DefaultValue (false)]
166 [MonitoringDescription ("Errors of this process are redirected.")]
167 [NotifyParentPropertyAttribute (true)]
168 public bool RedirectStandardError {
170 return(redirect_standard_error);
173 redirect_standard_error = value;
177 [DefaultValue (false)]
178 [MonitoringDescription ("Standard input of this process is redirected.")]
179 [NotifyParentPropertyAttribute (true)]
180 public bool RedirectStandardInput {
182 return(redirect_standard_input);
185 redirect_standard_input = value;
189 [DefaultValue (false)]
190 [MonitoringDescription ("Standart output of this process is redirected.")]
191 [NotifyParentPropertyAttribute (true)]
192 public bool RedirectStandardOutput {
194 return(redirect_standard_output);
197 redirect_standard_output = value;
201 public Encoding StandardErrorEncoding {
202 get { return encoding_stderr; }
203 set { encoding_stderr = value; }
206 public Encoding StandardOutputEncoding {
207 get { return encoding_stdout; }
208 set { encoding_stdout = value; }
211 [DefaultValue (true)]
212 [MonitoringDescription ("Use the shell to start this process.")]
213 [NotifyParentPropertyAttribute (true)]
214 public bool UseShellExecute {
216 return(use_shell_execute);
219 use_shell_execute = value;
224 [TypeConverter ("System.Diagnostics.Design.VerbConverter, " + Consts.AssemblySystem_Design)]
225 [MonitoringDescription ("The verb to apply to a used document.")]
226 [NotifyParentPropertyAttribute (true)]
236 static readonly string [] empty = new string [0];
238 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden), Browsable (false)]
239 public string[] Verbs {
241 string ext = filename == null | filename.Length == 0 ?
242 null : Path.GetExtension (filename);
250 switch (Environment.OSVersion.Platform) {
253 case (PlatformID)128:
254 return empty; // no verb on non-Windows
256 RegistryKey rk = null, rk2 = null, rk3 = null;
258 rk = Registry.ClassesRoot.OpenSubKey (ext);
259 string k = rk != null ? rk.GetValue (null) as string : null;
260 rk2 = k != null ? Registry.ClassesRoot.OpenSubKey (k) : null;
261 rk3 = rk2 != null ? rk2.OpenSubKey ("shell") : null;
262 return rk3 != null ? rk3.GetSubKeyNames () : null;
276 [DefaultValue (typeof (ProcessWindowStyle), "Normal")]
277 [MonitoringDescription ("The window style used to start this process.")]
278 [NotifyParentPropertyAttribute (true)]
279 public ProcessWindowStyle WindowStyle {
281 return(window_style);
284 window_style = value;
288 [RecommendedAsConfigurable (true), DefaultValue ("")]
289 [Editor ("System.Diagnostics.Design.WorkingDirectoryEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
290 [TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts.AssemblySystem_Design)]
291 [MonitoringDescription ("The initial directory for this process.")]
292 [NotifyParentPropertyAttribute (true)]
293 public string WorkingDirectory {
295 return(working_directory);
298 working_directory = value == null ? String.Empty : value;
302 [NotifyParentPropertyAttribute (true)]
303 public bool LoadUserProfile {
304 get { return load_user_profile; }
305 set { load_user_profile = value; }
308 [NotifyParentPropertyAttribute (true)]
309 public string UserName {
310 get { return username; }
311 set { username = value; }
314 [NotifyParentPropertyAttribute (true)]
315 public string Domain {
316 get { return domain; }
317 set { domain = value; }
320 public SecureString Password {
321 get { return password; }
322 set { password = value; }