Document HTTP_PROXY and NO_PROXY environment variables.
[mono.git] / mcs / class / System / System.Diagnostics / ProcessStartInfo.cs
1 //
2 // System.Diagnostics.ProcessStartInfo.cs
3 //
4 // Authors:
5 //   Dick Porter (dick@ximian.com)
6 //   Andreas Nahr (ClassDevelopment@A-SoftTech.com)
7 //
8 // (C) 2002 Ximian, Inc.  http://www.ximian.com
9 //
10
11 //
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:
19 // 
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 // 
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.
30 //
31
32 using Microsoft.Win32;
33 using System.Collections;
34 using System.Collections.Specialized;
35 using System.ComponentModel;
36 using System.IO;
37 using System.Security;
38 using System.Security.Permissions;
39 using System.Text;
40 using System.Runtime.InteropServices;
41
42 namespace System.Diagnostics 
43 {
44         [TypeConverter (typeof (ExpandableObjectConverter))]
45         [PermissionSet (SecurityAction.LinkDemand, Unrestricted = true)]
46         [StructLayout (LayoutKind.Sequential)]
47         public sealed class ProcessStartInfo 
48         {
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 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;
67
68                 public ProcessStartInfo() 
69                 {
70                 }
71
72                 public ProcessStartInfo(string filename) 
73                 {
74                         this.filename = filename;
75                 }
76
77                 public ProcessStartInfo(string filename, string arguments) 
78                 {
79                         this.filename = filename;
80                         this.arguments = arguments;
81                 }
82
83                 [RecommendedAsConfigurable (true), DefaultValue ("")]
84                 [TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts.AssemblySystem_Design)]
85
86                 [MonitoringDescription ("Command line agruments for this process.")]
87                 [NotifyParentPropertyAttribute (true)]
88                 public string Arguments {
89                         get {
90                                 return arguments ?? string.Empty;
91                         }
92                         set {
93                                 arguments = value;
94                         }
95                 }
96                 
97                 [DefaultValue (false)]
98                 [MonitoringDescription ("Start this process with a new window.")]
99                 [NotifyParentPropertyAttribute (true)]
100                 public bool CreateNoWindow {
101                         get {
102                                 return(create_no_window);
103                         }
104                         set {
105                                 create_no_window = value;
106                         }
107                 }
108
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 {
114                         get {
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 ();
121                                         } else {
122                                                 envVars = new CaseSensitiveStringDictionary ();                                         
123                                         }
124
125                                         foreach (DictionaryEntry entry in Environment.GetEnvironmentVariables ())
126                                                 envVars.Add ((string) entry.Key, (string) entry.Value);
127                                 }
128
129                                 return envVars;
130                         }
131                 }
132                 
133                 internal bool HaveEnvVars {
134                         get { return (envVars != null); }
135                 }
136                 
137                 [DefaultValue (false)]
138                 [MonitoringDescription ("Thread shows dialogboxes for errors.")]
139                 [NotifyParentPropertyAttribute (true)]
140                 public bool ErrorDialog {
141                         get {
142                                 return(error_dialog);
143                         }
144                         set {
145                                 error_dialog = value;
146                         }
147                 }
148                 
149                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden), Browsable (false)]
150                 public IntPtr ErrorDialogParentHandle {
151                         get {
152                                 return(error_dialog_parent_handle);
153                         }
154                         set {
155                                 error_dialog_parent_handle = value;
156                         }
157                 }
158                 
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 {
165                         get {
166                                 return filename ?? string.Empty;
167                         }
168                         set {
169                                 filename = value;
170                         }
171                 }
172                 
173                 [DefaultValue (false)]
174                 [MonitoringDescription ("Errors of this process are redirected.")]
175                 [NotifyParentPropertyAttribute (true)]
176                 public bool RedirectStandardError {
177                         get {
178                                 return(redirect_standard_error);
179                         }
180                         set {
181                                 redirect_standard_error = value;
182                         }
183                 }
184                 
185                 [DefaultValue (false)]
186                 [MonitoringDescription ("Standard input of this process is redirected.")]
187                 [NotifyParentPropertyAttribute (true)]
188                 public bool RedirectStandardInput {
189                         get {
190                                 return(redirect_standard_input);
191                         }
192                         set {
193                                 redirect_standard_input = value;
194                         }
195                 }
196                 
197                 [DefaultValue (false)]
198                 [MonitoringDescription ("Standard output of this process is redirected.")]
199                 [NotifyParentPropertyAttribute (true)]
200                 public bool RedirectStandardOutput {
201                         get {
202                                 return(redirect_standard_output);
203                         }
204                         set {
205                                 redirect_standard_output = value;
206                         }
207                 }
208                 
209                 public Encoding StandardErrorEncoding {
210                         get { return encoding_stderr; }
211                         set { encoding_stderr = value; }
212                 }
213
214                 public Encoding StandardOutputEncoding {
215                         get { return encoding_stdout; }
216                         set { encoding_stdout = value; }
217                 }
218                 
219                 [DefaultValue (true)]
220                 [MonitoringDescription ("Use the shell to start this process.")]
221                 [NotifyParentPropertyAttribute (true)]
222                 public bool UseShellExecute {
223                         get {
224                                 return(use_shell_execute);
225                         }
226                         set {
227                                 use_shell_execute = value;
228                         }
229                 }
230                 
231                 [DefaultValue ("")]
232                 [TypeConverter ("System.Diagnostics.Design.VerbConverter, " + Consts.AssemblySystem_Design)]
233                 [MonitoringDescription ("The verb to apply to a used document.")]
234                 [NotifyParentPropertyAttribute (true)]
235                 public string Verb {
236                         get {
237                                 return verb ?? string.Empty;
238                         }
239                         set {
240                                 verb = value;
241                         }
242                 }
243
244                 static readonly string [] empty = new string [0];
245
246                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden), Browsable (false)]
247                 public string[] Verbs {
248                         get {
249 #if MOBILE
250                                 return empty;
251 #else
252                                 switch (Environment.OSVersion.Platform) {
253                                 case (PlatformID)4:
254                                 case (PlatformID)6:
255                                 case (PlatformID)128:
256                                         return empty; // no verb on non-Windows
257                                 default:
258                                         string ext = filename == null | filename.Length == 0 ?
259                                                 null : Path.GetExtension (filename);
260                                         if (ext == null)
261                                                 return empty;
262
263                                         RegistryKey rk = null, rk2 = null, rk3 = null;
264                                         try {
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;
270                                         } finally {
271                                                 if (rk3 != null)
272                                                         rk3.Close ();
273                                                 if (rk2 != null)
274                                                         rk2.Close ();
275                                                 if (rk != null)
276                                                         rk.Close ();
277                                         }
278                                 }
279 #endif
280                         }
281                 }
282                 
283                 [DefaultValue (typeof (ProcessWindowStyle), "Normal")]
284                 [MonitoringDescription ("The window style used to start this process.")]
285                 [NotifyParentPropertyAttribute (true)]
286                 public ProcessWindowStyle WindowStyle {
287                         get {
288                                 return(window_style);
289                         }
290                         set {
291                                 window_style = value;
292                         }
293                 }
294                 
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 {
301                         get {
302                                 return working_directory ?? string.Empty;
303                         }
304                         set {
305                                 working_directory = value;
306                         }
307                 }
308
309                 [NotifyParentPropertyAttribute (true)]
310                 public bool LoadUserProfile {
311                         get { return load_user_profile; }
312                         set { load_user_profile = value; }
313                 }
314
315                 [NotifyParentPropertyAttribute (true)]
316                 public string UserName {
317                         get { return username ?? string.Empty; }
318                         set { username = value; }
319                 }
320
321                 [NotifyParentPropertyAttribute (true)]
322                 public string Domain {
323                         get { return domain ?? string.Empty; }
324                         set { domain = value; }
325                 }
326
327                 public SecureString Password {
328                         get { return password; }
329                         set { password = value; }
330                 }
331         }
332 }