2010-06-21 Atsushi Enomoto <atsushi@ximian.com>
[mcs.git] / class / System / System.Diagnostics / ProcessStartInfo.cs
blob41936f479e53b85b667046fffa0421e658abe8b5
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 //
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.
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;
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;
63 #if NET_2_0
64 private SecureString password;
65 #else
66 private object password; // dummy
67 #endif
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.")]
89 #if NET_2_0
90 [NotifyParentPropertyAttribute (true)]
91 #endif
92 public string Arguments {
93 get {
94 return(arguments);
96 set {
97 arguments = value;
101 [DefaultValue (false)]
102 [MonitoringDescription ("Start this process with a new window.")]
103 #if NET_2_0
104 [NotifyParentPropertyAttribute (true)]
105 #endif
106 public bool CreateNoWindow {
107 get {
108 return(create_no_window);
110 set {
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.")]
118 #if NET_2_0
119 [NotifyParentPropertyAttribute (true)]
120 #endif
121 public StringDictionary EnvironmentVariables {
122 get {
123 if (envVars == null) {
124 envVars = new ProcessStringDictionary ();
125 foreach (DictionaryEntry entry in Environment.GetEnvironmentVariables ())
126 envVars.Add ((string) entry.Key, (string) entry.Value);
129 return envVars;
133 internal bool HaveEnvVars {
134 get { return (envVars != null); }
137 [DefaultValue (false)]
138 [MonitoringDescription ("Thread shows dialogboxes for errors.")]
139 #if NET_2_0
140 [NotifyParentPropertyAttribute (true)]
141 #endif
142 public bool ErrorDialog {
143 get {
144 return(error_dialog);
146 set {
147 error_dialog = value;
151 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden), Browsable (false)]
152 public IntPtr ErrorDialogParentHandle {
153 get {
154 return(error_dialog_parent_handle);
156 set {
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.")]
165 #if NET_2_0
166 [NotifyParentPropertyAttribute (true)]
167 #endif
168 public string FileName {
169 get {
170 return(filename);
172 set {
173 filename = value;
177 [DefaultValue (false)]
178 [MonitoringDescription ("Errors of this process are redirected.")]
179 #if NET_2_0
180 [NotifyParentPropertyAttribute (true)]
181 #endif
182 public bool RedirectStandardError {
183 get {
184 return(redirect_standard_error);
186 set {
187 redirect_standard_error = value;
191 [DefaultValue (false)]
192 [MonitoringDescription ("Standard input of this process is redirected.")]
193 #if NET_2_0
194 [NotifyParentPropertyAttribute (true)]
195 #endif
196 public bool RedirectStandardInput {
197 get {
198 return(redirect_standard_input);
200 set {
201 redirect_standard_input = value;
205 [DefaultValue (false)]
206 [MonitoringDescription ("Standart output of this process is redirected.")]
207 #if NET_2_0
208 [NotifyParentPropertyAttribute (true)]
209 #endif
210 public bool RedirectStandardOutput {
211 get {
212 return(redirect_standard_output);
214 set {
215 redirect_standard_output = value;
219 #if NET_2_0
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; }
229 #endif
231 [DefaultValue (true)]
232 [MonitoringDescription ("Use the shell to start this process.")]
233 #if NET_2_0
234 [NotifyParentPropertyAttribute (true)]
235 #endif
236 public bool UseShellExecute {
237 get {
238 return(use_shell_execute);
240 set {
241 use_shell_execute = value;
245 [DefaultValue ("")]
246 [TypeConverter ("System.Diagnostics.Design.VerbConverter, " + Consts.AssemblySystem_Design)]
247 [MonitoringDescription ("The verb to apply to a used document.")]
248 #if NET_2_0
249 [NotifyParentPropertyAttribute (true)]
250 #endif
251 public string Verb {
252 get {
253 return(verb);
255 set {
256 verb = value;
260 static readonly string [] empty = new string [0];
262 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden), Browsable (false)]
263 public string[] Verbs {
264 get {
265 string ext = filename == null | filename.Length == 0 ?
266 null : Path.GetExtension (filename);
267 if (ext == null)
268 return empty;
270 #if MONOTOUCH
271 return empty;
272 #else
274 switch (Environment.OSVersion.Platform) {
275 case (PlatformID)4:
276 case (PlatformID)6:
277 case (PlatformID)128:
278 return empty; // no verb on non-Windows
279 default:
280 RegistryKey rk = null, rk2 = null, rk3 = null;
281 try {
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;
287 } finally {
288 if (rk3 != null)
289 rk3.Close ();
290 if (rk2 != null)
291 rk2.Close ();
292 if (rk != null)
293 rk.Close ();
296 #endif
300 [DefaultValue (typeof (ProcessWindowStyle), "Normal")]
301 [MonitoringDescription ("The window style used to start this process.")]
302 #if NET_2_0
303 [NotifyParentPropertyAttribute (true)]
304 #endif
305 public ProcessWindowStyle WindowStyle {
306 get {
307 return(window_style);
309 set {
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.")]
318 #if NET_2_0
319 [NotifyParentPropertyAttribute (true)]
320 #endif
321 public string WorkingDirectory {
322 get {
323 return(working_directory);
325 set {
326 working_directory = value == null ? String.Empty : value;
330 #if NET_2_0
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; }
353 #endif