mscorlib(4.0.0.0) API with additions
ProcessStartInfo.cs
1 using Microsoft.Win32;
2 using System.Collections;
6 using System.IO;
7 using System.Security;
9 using System.Text;
10 
11 namespace System.Diagnostics
12 {
15  [PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust")]
16  [HostProtection(SecurityAction.LinkDemand, SharedState = true, SelfAffectingProcessMgmt = true)]
17  public sealed class ProcessStartInfo
18  {
19  private string fileName;
20 
21  private string arguments;
22 
23  private string directory;
24 
25  private string verb;
26 
27  private ProcessWindowStyle windowStyle;
28 
29  private bool errorDialog;
30 
31  private IntPtr errorDialogParentHandle;
32 
33  private bool useShellExecute = true;
34 
35  private string userName;
36 
37  private string domain;
38 
39  private SecureString password;
40 
41  private string passwordInClearText;
42 
43  private bool loadUserProfile;
44 
45  private bool redirectStandardInput;
46 
47  private bool redirectStandardOutput;
48 
49  private bool redirectStandardError;
50 
51  private Encoding standardOutputEncoding;
52 
53  private Encoding standardErrorEncoding;
54 
55  private bool createNoWindow;
56 
57  private WeakReference weakParentProcess;
58 
59  internal StringDictionary environmentVariables;
60 
61  private IDictionary<string, string> environment;
62 
65  [DefaultValue("")]
66  [TypeConverter("System.Diagnostics.Design.VerbConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
67  [MonitoringDescription("ProcessVerb")]
68  [NotifyParentProperty(true)]
69  public string Verb
70  {
71  get
72  {
73  if (verb == null)
74  {
75  return string.Empty;
76  }
77  return verb;
78  }
79  set
80  {
81  verb = value;
82  }
83  }
84 
87  [DefaultValue("")]
88  [MonitoringDescription("ProcessArguments")]
89  [SettingsBindable(true)]
90  [TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
91  [NotifyParentProperty(true)]
92  public string Arguments
93  {
94  get
95  {
96  if (arguments == null)
97  {
98  return string.Empty;
99  }
100  return arguments;
101  }
102  set
103  {
104  arguments = value;
105  }
106  }
107 
111  [DefaultValue(false)]
112  [MonitoringDescription("ProcessCreateNoWindow")]
113  [NotifyParentProperty(true)]
114  public bool CreateNoWindow
115  {
116  get
117  {
118  return createNoWindow;
119  }
120  set
121  {
122  createNoWindow = value;
123  }
124  }
125 
128  [Editor("System.Diagnostics.Design.StringDictionaryEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
130  [DefaultValue(null)]
131  [MonitoringDescription("ProcessEnvironmentVariables")]
132  [NotifyParentProperty(true)]
134  {
135  get
136  {
137  if (environmentVariables == null)
138  {
139  environmentVariables = new StringDictionaryWithComparer();
140  if (weakParentProcess == null || !weakParentProcess.IsAlive || ((Component)weakParentProcess.Target).Site == null || !((Component)weakParentProcess.Target).Site.DesignMode)
141  {
142  foreach (DictionaryEntry environmentVariable in System.Environment.GetEnvironmentVariables())
143  {
144  environmentVariables.Add((string)environmentVariable.Key, (string)environmentVariable.Value);
145  }
146  }
147  }
148  return environmentVariables;
149  }
150  }
151 
155  [DefaultValue(null)]
156  [NotifyParentProperty(true)]
158  {
159  get
160  {
161  if (environment == null)
162  {
163  environment = EnvironmentVariables.AsGenericDictionary();
164  }
165  return environment;
166  }
167  }
168 
172  [DefaultValue(false)]
173  [MonitoringDescription("ProcessRedirectStandardInput")]
174  [NotifyParentProperty(true)]
175  public bool RedirectStandardInput
176  {
177  get
178  {
179  return redirectStandardInput;
180  }
181  set
182  {
183  redirectStandardInput = value;
184  }
185  }
186 
190  [DefaultValue(false)]
191  [MonitoringDescription("ProcessRedirectStandardOutput")]
192  [NotifyParentProperty(true)]
193  public bool RedirectStandardOutput
194  {
195  get
196  {
197  return redirectStandardOutput;
198  }
199  set
200  {
201  redirectStandardOutput = value;
202  }
203  }
204 
208  [DefaultValue(false)]
209  [MonitoringDescription("ProcessRedirectStandardError")]
210  [NotifyParentProperty(true)]
211  public bool RedirectStandardError
212  {
213  get
214  {
215  return redirectStandardError;
216  }
217  set
218  {
219  redirectStandardError = value;
220  }
221  }
222 
226  {
227  get
228  {
229  return standardErrorEncoding;
230  }
231  set
232  {
233  standardErrorEncoding = value;
234  }
235  }
236 
240  {
241  get
242  {
243  return standardOutputEncoding;
244  }
245  set
246  {
247  standardOutputEncoding = value;
248  }
249  }
250 
254  [DefaultValue(true)]
255  [MonitoringDescription("ProcessUseShellExecute")]
256  [NotifyParentProperty(true)]
257  public bool UseShellExecute
258  {
259  get
260  {
261  return useShellExecute;
262  }
263  set
264  {
265  useShellExecute = value;
266  }
267  }
268 
271  [Browsable(false)]
273  public string[] Verbs
274  {
275  get
276  {
277  ArrayList arrayList = new ArrayList();
278  RegistryKey registryKey = null;
279  string extension = Path.GetExtension(FileName);
280  try
281  {
282  if (extension != null && extension.Length > 0)
283  {
284  registryKey = Registry.ClassesRoot.OpenSubKey(extension);
285  if (registryKey != null)
286  {
287  string str = (string)registryKey.GetValue(string.Empty);
288  registryKey.Close();
289  registryKey = Registry.ClassesRoot.OpenSubKey(str + "\\shell");
290  if (registryKey != null)
291  {
292  string[] subKeyNames = registryKey.GetSubKeyNames();
293  for (int i = 0; i < subKeyNames.Length; i++)
294  {
295  if (string.Compare(subKeyNames[i], "new", StringComparison.OrdinalIgnoreCase) != 0)
296  {
297  arrayList.Add(subKeyNames[i]);
298  }
299  }
300  registryKey.Close();
301  registryKey = null;
302  }
303  }
304  }
305  }
306  finally
307  {
308  registryKey?.Close();
309  }
310  string[] array = new string[arrayList.Count];
311  arrayList.CopyTo(array, 0);
312  return array;
313  }
314  }
315 
318  [NotifyParentProperty(true)]
319  public string UserName
320  {
321  get
322  {
323  if (userName == null)
324  {
325  return string.Empty;
326  }
327  return userName;
328  }
329  set
330  {
331  userName = value;
332  }
333  }
334 
337  public SecureString Password
338  {
339  get
340  {
341  return password;
342  }
343  set
344  {
345  password = value;
346  }
347  }
348 
351  [Browsable(false)]
353  public string PasswordInClearText
354  {
355  get
356  {
357  return passwordInClearText;
358  }
359  set
360  {
361  passwordInClearText = value;
362  }
363  }
364 
367  [NotifyParentProperty(true)]
368  public string Domain
369  {
370  get
371  {
372  if (domain == null)
373  {
374  return string.Empty;
375  }
376  return domain;
377  }
378  set
379  {
380  domain = value;
381  }
382  }
383 
387  [NotifyParentProperty(true)]
388  public bool LoadUserProfile
389  {
390  get
391  {
392  return loadUserProfile;
393  }
394  set
395  {
396  loadUserProfile = value;
397  }
398  }
399 
402  [DefaultValue("")]
403  [Editor("System.Diagnostics.Design.StartFileNameEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
404  [MonitoringDescription("ProcessFileName")]
405  [SettingsBindable(true)]
406  [TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
407  [NotifyParentProperty(true)]
408  public string FileName
409  {
410  get
411  {
412  if (fileName == null)
413  {
414  return string.Empty;
415  }
416  return fileName;
417  }
418  set
419  {
420  fileName = value;
421  }
422  }
423 
426  [DefaultValue("")]
427  [MonitoringDescription("ProcessWorkingDirectory")]
428  [Editor("System.Diagnostics.Design.WorkingDirectoryEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
429  [SettingsBindable(true)]
430  [TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
431  [NotifyParentProperty(true)]
432  public string WorkingDirectory
433  {
434  get
435  {
436  if (directory == null)
437  {
438  return string.Empty;
439  }
440  return directory;
441  }
442  set
443  {
444  directory = value;
445  }
446  }
447 
451  [DefaultValue(false)]
452  [MonitoringDescription("ProcessErrorDialog")]
453  [NotifyParentProperty(true)]
454  public bool ErrorDialog
455  {
456  get
457  {
458  return errorDialog;
459  }
460  set
461  {
462  errorDialog = value;
463  }
464  }
465 
468  [Browsable(false)]
471  {
472  get
473  {
474  return errorDialogParentHandle;
475  }
476  set
477  {
478  errorDialogParentHandle = value;
479  }
480  }
481 
485  [DefaultValue(ProcessWindowStyle.Normal)]
486  [MonitoringDescription("ProcessWindowStyle")]
487  [NotifyParentProperty(true)]
489  {
490  get
491  {
492  return windowStyle;
493  }
494  set
495  {
496  if (!Enum.IsDefined(typeof(ProcessWindowStyle), value))
497  {
498  throw new InvalidEnumArgumentException("value", (int)value, typeof(ProcessWindowStyle));
499  }
500  windowStyle = value;
501  }
502  }
503 
506  {
507  }
508 
509  internal ProcessStartInfo(Process parent)
510  {
511  weakParentProcess = new WeakReference(parent);
512  }
513 
516  public ProcessStartInfo(string fileName)
517  {
518  this.fileName = fileName;
519  }
520 
524  public ProcessStartInfo(string fileName, string arguments)
525  {
526  this.fileName = fileName;
527  this.arguments = arguments;
528  }
529  }
530 }
static string GetExtension(string path)
Returns the extension of the specified path string.
Definition: Path.cs:405
Represents a character encoding.To browse the .NET Framework source code for this type,...
Definition: Encoding.cs:15
bool LoadUserProfile
Gets or sets a value that indicates whether the Windows user profile is to be loaded from the registr...
string Arguments
Gets or sets the set of command-line arguments to use when starting the application.
StringComparison
Specifies the culture, case, and sort rules to be used by certain overloads of the M:System....
string Verb
Gets or sets the verb to use when opening the application or document specified by the P:System....
virtual void Add(string key, string value)
Adds an entry with the specified key and value into the T:System.Collections.Specialized....
virtual int Count
Gets the number of elements actually contained in the T:System.Collections.ArrayList.
Definition: ArrayList.cs:2255
Implements a hash table with the key and the value strongly typed to be strings rather than objects.
Definition: __Canon.cs:3
Provides a type converter to convert expandable objects to and from various other representations.
ProcessStartInfo(string fileName)
Initializes a new instance of the T:System.Diagnostics.ProcessStartInfo class and specifies a file na...
IntPtr ErrorDialogParentHandle
Gets or sets the window handle to use when an error dialog box is shown for a process that cannot be ...
bool RedirectStandardError
Gets or sets a value that indicates whether the error output of an application is written to the P:Sy...
bool UseShellExecute
Gets or sets a value indicating whether to use the operating system shell to start the process.
static IDictionary GetEnvironmentVariables()
Retrieves all environment variable names and their values from the current process.
Definition: Environment.cs:954
ProcessWindowStyle
Specified how a new window should appear when the system starts a process.
Represents a weak reference, which references an object while still allowing that object to be reclai...
Specifies a set of values that are used when you start a process.
The exception thrown when using invalid arguments that are enumerators.
SecurityAction
Specifies the security actions that can be performed using declarative security.
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
static bool IsDefined(Type enumType, object value)
Returns an indication whether a constant with a specified value exists in a specified enumeration.
Definition: Enum.cs:577
string UserName
Gets or sets the user name to be used when starting the process.
Represents a collection that can contain many different types of permissions.
ProcessStartInfo()
Initializes a new instance of the T:System.Diagnostics.ProcessStartInfo class without specifying a fi...
Provides the base class for enumerations.
Definition: Enum.cs:14
string WorkingDirectory
When the P:System.Diagnostics.ProcessStartInfo.UseShellExecute property is false, gets or sets the wo...
Represents text that should be kept confidential, such as by deleting it from computer memory when no...
Definition: SecureString.cs:11
string FileName
Gets or sets the application or document to start.
A platform-specific type that is used to represent a pointer or a handle.
Definition: IntPtr.cs:14
bool ErrorDialog
Gets or sets a value indicating whether an error dialog box is displayed to the user if the process c...
Provides access to local and remote processes and enables you to start and stop local system processe...
Definition: Process.cs:25
Provides the base implementation for the T:System.ComponentModel.IComponent interface and enables obj...
Definition: Component.cs:9
bool RedirectStandardOutput
Gets or sets a value that indicates whether the textual output of an application is written to the P:...
virtual void CopyTo(Array array)
Copies the entire T:System.Collections.ArrayList to a compatible one-dimensional T:System....
Definition: ArrayList.cs:2516
string []? Verbs
Gets the set of verbs associated with the type of file specified by the P:System.Diagnostics....
bool RedirectStandardInput
Gets or sets a value indicating whether the input for an application is read from the P:System....
bool CreateNoWindow
Gets or sets a value indicating whether to start the process in a new window.
virtual int Add(object value)
Adds an object to the end of the T:System.Collections.ArrayList.
Definition: ArrayList.cs:2381
ProcessStartInfo(string fileName, string arguments)
Initializes a new instance of the T:System.Diagnostics.ProcessStartInfo class, specifies an applicati...
string PasswordInClearText
Gets or sets the user password in clear text to use when starting the process.
SecureString Password
Gets or sets a secure string that contains the user password to use when starting the process.
DesignerSerializationVisibility
Specifies the visibility a property has to the design-time serializer.
Encoding StandardOutputEncoding
Gets or sets the preferred encoding for standard output.
object Value
Gets or sets the value in the key/value pair.
object Key
Gets or sets the key in the key/value pair.
ProcessWindowStyle WindowStyle
Gets or sets the window state to use when the process is started.
Encoding StandardErrorEncoding
Gets or sets the preferred encoding for error output.
Defines a dictionary key/value pair that can be set or retrieved.
string Domain
Gets or sets a value that identifies the domain to use when starting the process.
StringDictionary EnvironmentVariables
Gets search paths for files, directories for temporary files, application-specific options,...
Provides a unified way of converting types of values to other types, as well as for accessing standar...
Performs operations on T:System.String instances that contain file or directory path information....
Definition: Path.cs:13
Implements the T:System.Collections.IList interface using an array whose size is dynamically increase...
Definition: ArrayList.cs:14