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;
54 private string working_directory;
55 private StringDictionary 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 {
90 return arguments ?? string.Empty;
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 // check for non-Unix platforms - see FAQ for more details
117 // http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F
118 int platform = (int) Environment.OSVersion.Platform;
119 if ((platform != 4) && (platform != 128)) {
120 envVars = new StringDictionary ();
122 envVars = new CaseSensitiveStringDictionary ();
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.")]
139 [NotifyParentPropertyAttribute (true)]
140 public bool ErrorDialog {
142 return(error_dialog);
145 error_dialog = value;
149 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden), Browsable (false)]
150 public IntPtr ErrorDialogParentHandle {
152 return(error_dialog_parent_handle);
155 error_dialog_parent_handle = value;
159 [RecommendedAsConfigurable (true), DefaultValue ("")]
160 [Editor ("System.Diagnostics.Design.StartFileNameEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
161 [TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts.AssemblySystem_Design)]
162 [MonitoringDescription ("The name of the resource to start this process.")]
163 [NotifyParentPropertyAttribute (true)]
164 public string FileName {
166 return filename ?? string.Empty;
173 [DefaultValue (false)]
174 [MonitoringDescription ("Errors of this process are redirected.")]
175 [NotifyParentPropertyAttribute (true)]
176 public bool RedirectStandardError {
178 return(redirect_standard_error);
181 redirect_standard_error = value;
185 [DefaultValue (false)]
186 [MonitoringDescription ("Standard input of this process is redirected.")]
187 [NotifyParentPropertyAttribute (true)]
188 public bool RedirectStandardInput {
190 return(redirect_standard_input);
193 redirect_standard_input = value;
197 [DefaultValue (false)]
198 [MonitoringDescription ("Standard output of this process is redirected.")]
199 [NotifyParentPropertyAttribute (true)]
200 public bool RedirectStandardOutput {
202 return(redirect_standard_output);
205 redirect_standard_output = value;
209 public Encoding StandardErrorEncoding {
210 get { return encoding_stderr; }
211 set { encoding_stderr = value; }
214 public Encoding StandardOutputEncoding {
215 get { return encoding_stdout; }
216 set { encoding_stdout = value; }
219 [DefaultValue (true)]
220 [MonitoringDescription ("Use the shell to start this process.")]
221 [NotifyParentPropertyAttribute (true)]
222 public bool UseShellExecute {
224 return(use_shell_execute);
227 use_shell_execute = value;
232 [TypeConverter ("System.Diagnostics.Design.VerbConverter, " + Consts.AssemblySystem_Design)]
233 [MonitoringDescription ("The verb to apply to a used document.")]
234 [NotifyParentPropertyAttribute (true)]
237 return verb ?? string.Empty;
244 static readonly string [] empty = new string [0];
246 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden), Browsable (false)]
247 public string[] Verbs {
252 switch (Environment.OSVersion.Platform) {
255 case (PlatformID)128:
256 return empty; // no verb on non-Windows
258 string ext = filename == null | filename.Length == 0 ?
259 null : Path.GetExtension (filename);
263 RegistryKey rk = null, rk2 = null, rk3 = null;
265 rk = Registry.ClassesRoot.OpenSubKey (ext);
266 string k = rk != null ? rk.GetValue (null) as string : null;
267 rk2 = k != null ? Registry.ClassesRoot.OpenSubKey (k) : null;
268 rk3 = rk2 != null ? rk2.OpenSubKey ("shell") : null;
269 return rk3 != null ? rk3.GetSubKeyNames () : null;
283 [DefaultValue (typeof (ProcessWindowStyle), "Normal")]
284 [MonitoringDescription ("The window style used to start this process.")]
285 [NotifyParentPropertyAttribute (true)]
286 public ProcessWindowStyle WindowStyle {
288 return(window_style);
291 window_style = value;
295 [RecommendedAsConfigurable (true), DefaultValue ("")]
296 [Editor ("System.Diagnostics.Design.WorkingDirectoryEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
297 [TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts.AssemblySystem_Design)]
298 [MonitoringDescription ("The initial directory for this process.")]
299 [NotifyParentPropertyAttribute (true)]
300 public string WorkingDirectory {
302 return working_directory ?? string.Empty;
305 working_directory = value;
309 [NotifyParentPropertyAttribute (true)]
310 public bool LoadUserProfile {
311 get { return load_user_profile; }
312 set { load_user_profile = value; }
315 [NotifyParentPropertyAttribute (true)]
316 public string UserName {
317 get { return username ?? string.Empty; }
318 set { username = value; }
321 [NotifyParentPropertyAttribute (true)]
322 public string Domain {
323 get { return domain ?? string.Empty; }
324 set { domain = value; }
327 public SecureString Password {
328 get { return password; }
329 set { password = value; }