Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ProcessStartInfo.cs « System.Diagnostics « System « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 41936f479e53b85b667046fffa0421e658abe8b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
//
// System.Diagnostics.ProcessStartInfo.cs
//
// Authors:
//   Dick Porter (dick@ximian.com)
//   Andreas Nahr (ClassDevelopment@A-SoftTech.com)
//
// (C) 2002 Ximian, Inc.  http://www.ximian.com
//

//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

using Microsoft.Win32;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.IO;
using System.Security;
using System.Security.Permissions;
using System.Text;

namespace System.Diagnostics 
{
	[TypeConverter (typeof (ExpandableObjectConverter))]
	[PermissionSet (SecurityAction.LinkDemand, Unrestricted = true)]
	public sealed class ProcessStartInfo 
	{
		/* keep these fields in this order and in sync with metadata/process.h */
		private string arguments = "";
		private IntPtr error_dialog_parent_handle = (IntPtr)0;
		private string filename = "";
		private string verb = "";
		private string working_directory = "";
		private ProcessStringDictionary envVars;
		private bool create_no_window = false;
		private bool error_dialog = false;
		private bool redirect_standard_error = false;
		private bool redirect_standard_input = false;
		private bool redirect_standard_output = false;
		private bool use_shell_execute = true;
		private ProcessWindowStyle window_style = ProcessWindowStyle.Normal;
		private Encoding encoding_stderr, encoding_stdout;
		private string username, domain;
#if NET_2_0
		private SecureString password;
#else
		private object password; // dummy
#endif
		private bool load_user_profile;

		public ProcessStartInfo() 
		{
		}

		public ProcessStartInfo(string filename) 
		{
			this.filename = filename;
		}

		public ProcessStartInfo(string filename, string arguments) 
		{
			this.filename = filename;
			this.arguments = arguments;
		}

		[RecommendedAsConfigurable (true), DefaultValue ("")]
		[TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts.AssemblySystem_Design)]

		[MonitoringDescription ("Command line agruments for this process.")]
#if NET_2_0
		[NotifyParentPropertyAttribute (true)]
#endif
		public string Arguments {
			get {
				return(arguments);
			}
			set {
				arguments = value;
			}
		}
		
		[DefaultValue (false)]
		[MonitoringDescription ("Start this process with a new window.")]
#if NET_2_0
		[NotifyParentPropertyAttribute (true)]
#endif
		public bool CreateNoWindow {
			get {
				return(create_no_window);
			}
			set {
				create_no_window = value;
			}
		}

		[DesignerSerializationVisibility (DesignerSerializationVisibility.Content), DefaultValue (null)]
		[Editor ("System.Diagnostics.Design.StringDictionaryEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
		[MonitoringDescription ("Environment variables used for this process.")]
#if NET_2_0
		[NotifyParentPropertyAttribute (true)]
#endif
		public StringDictionary EnvironmentVariables {
			get {
				if (envVars == null) {
					envVars = new ProcessStringDictionary ();
					foreach (DictionaryEntry entry in Environment.GetEnvironmentVariables ())
						envVars.Add ((string) entry.Key, (string) entry.Value);
				}

				return envVars;
			}
		}
		
		internal bool HaveEnvVars {
			get { return (envVars != null); }
		}
		
		[DefaultValue (false)]
		[MonitoringDescription ("Thread shows dialogboxes for errors.")]
#if NET_2_0
		[NotifyParentPropertyAttribute (true)]
#endif
		public bool ErrorDialog {
			get {
				return(error_dialog);
			}
			set {
				error_dialog = value;
			}
		}
		
		[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden), Browsable (false)]
		public IntPtr ErrorDialogParentHandle {
			get {
				return(error_dialog_parent_handle);
			}
			set {
				error_dialog_parent_handle = value;
			}
		}
		
		[RecommendedAsConfigurable (true), DefaultValue ("")]
		[Editor ("System.Diagnostics.Design.StartFileNameEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
		[TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts.AssemblySystem_Design)]
		[MonitoringDescription ("The name of the resource to start this process.")]
#if NET_2_0
		[NotifyParentPropertyAttribute (true)]
#endif
		public string FileName {
			get {
				return(filename);
			}
			set {
				filename = value;
			}
		}
		
		[DefaultValue (false)]
		[MonitoringDescription ("Errors of this process are redirected.")]
#if NET_2_0
		[NotifyParentPropertyAttribute (true)]
#endif
		public bool RedirectStandardError {
			get {
				return(redirect_standard_error);
			}
			set {
				redirect_standard_error = value;
			}
		}
		
		[DefaultValue (false)]
		[MonitoringDescription ("Standard input of this process is redirected.")]
#if NET_2_0
		[NotifyParentPropertyAttribute (true)]
#endif
		public bool RedirectStandardInput {
			get {
				return(redirect_standard_input);
			}
			set {
				redirect_standard_input = value;
			}
		}
		
		[DefaultValue (false)]
		[MonitoringDescription ("Standart output of this process is redirected.")]
#if NET_2_0
		[NotifyParentPropertyAttribute (true)]
#endif
		public bool RedirectStandardOutput {
			get {
				return(redirect_standard_output);
			}
			set {
				redirect_standard_output = value;
			}
		}
		
#if NET_2_0
		public Encoding StandardErrorEncoding {
			get { return encoding_stderr; }
			set { encoding_stderr = value; }
		}

		public Encoding StandardOutputEncoding {
			get { return encoding_stdout; }
			set { encoding_stdout = value; }
		}
#endif
		
		[DefaultValue (true)]
		[MonitoringDescription ("Use the shell to start this process.")]
#if NET_2_0
		[NotifyParentPropertyAttribute (true)]
#endif
		public bool UseShellExecute {
			get {
				return(use_shell_execute);
			}
			set {
				use_shell_execute = value;
			}
		}
		
		[DefaultValue ("")]
		[TypeConverter ("System.Diagnostics.Design.VerbConverter, " + Consts.AssemblySystem_Design)]
		[MonitoringDescription ("The verb to apply to a used document.")]
#if NET_2_0
		[NotifyParentPropertyAttribute (true)]
#endif
		public string Verb {
			get {
				return(verb);
			}
			set {
				verb = value;
			}
		}

		static readonly string [] empty = new string [0];

		[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden), Browsable (false)]
		public string[] Verbs {
			get {
				string ext = filename == null | filename.Length == 0 ? 
					null : Path.GetExtension (filename);
				if (ext == null)
					return empty;

#if MONOTOUCH
				return empty;
#else

				switch (Environment.OSVersion.Platform) {
				case (PlatformID)4:
				case (PlatformID)6:
				case (PlatformID)128:
					return empty; // no verb on non-Windows
				default:
					RegistryKey rk = null, rk2 = null, rk3 = null;
					try {
						rk = Registry.ClassesRoot.OpenSubKey (ext);
						string k = rk != null ? rk.GetValue (null) as string : null;
						rk2 = k != null ? Registry.ClassesRoot.OpenSubKey (k) : null;
						rk3 = rk2 != null ? rk2.OpenSubKey ("shell") : null;
						return rk3 != null ? rk3.GetSubKeyNames () : null;
					} finally {
						if (rk3 != null)
							rk3.Close ();
						if (rk2 != null)
							rk2.Close ();
						if (rk != null)
							rk.Close ();
					}
				}
#endif
			}
		}
		
		[DefaultValue (typeof (ProcessWindowStyle), "Normal")]
		[MonitoringDescription ("The window style used to start this process.")]
#if NET_2_0
		[NotifyParentPropertyAttribute (true)]
#endif
		public ProcessWindowStyle WindowStyle {
			get {
				return(window_style);
			}
			set {
				window_style = value;
			}
		}
		
		[RecommendedAsConfigurable (true), DefaultValue ("")]
		[Editor ("System.Diagnostics.Design.WorkingDirectoryEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
		[TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts.AssemblySystem_Design)]
		[MonitoringDescription ("The initial directory for this process.")]
#if NET_2_0
		[NotifyParentPropertyAttribute (true)]
#endif
		public string WorkingDirectory {
			get {
				return(working_directory);
			}
			set {
				working_directory = value == null ? String.Empty : value;
			}
		}

#if NET_2_0
		[NotifyParentPropertyAttribute (true)]
		public bool LoadUserProfile {
			get { return load_user_profile; }
			set { load_user_profile = value; }
		}

		[NotifyParentPropertyAttribute (true)]
		public string UserName {
			get { return username; }
			set { username = value; }
		}

		[NotifyParentPropertyAttribute (true)]
		public string Domain {
			get { return domain; }
			set { domain = value; }
		}

		public SecureString Password {
			get { return password; }
			set { password = value; }
		}
#endif
	}
}