PageRenderTime 1158ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/mcs/class/System/System.Diagnostics/ProcessStartInfo.cs

https://github.com/iainlane/mono
C# | 357 lines | 295 code | 32 blank | 30 comment | 19 complexity | 83e50c2bf747b08fadc0f44cd61eb7ff MD5 | raw file
  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. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  30. using Microsoft.Win32;
  31. using System.Collections;
  32. using System.Collections.Specialized;
  33. using System.ComponentModel;
  34. using System.IO;
  35. using System.Security;
  36. using System.Security.Permissions;
  37. using System.Text;
  38. using System.Runtime.InteropServices;
  39. namespace System.Diagnostics
  40. {
  41. [TypeConverter (typeof (ExpandableObjectConverter))]
  42. [PermissionSet (SecurityAction.LinkDemand, Unrestricted = true)]
  43. [StructLayout (LayoutKind.Sequential)]
  44. public sealed class ProcessStartInfo
  45. {
  46. /* keep these fields in this order and in sync with metadata/process.h */
  47. private string arguments = "";
  48. private IntPtr error_dialog_parent_handle = (IntPtr)0;
  49. private string filename = "";
  50. private string verb = "";
  51. private string working_directory = "";
  52. private ProcessStringDictionary envVars;
  53. private bool create_no_window = false;
  54. private bool error_dialog = false;
  55. private bool redirect_standard_error = false;
  56. private bool redirect_standard_input = false;
  57. private bool redirect_standard_output = false;
  58. private bool use_shell_execute = true;
  59. private ProcessWindowStyle window_style = ProcessWindowStyle.Normal;
  60. private Encoding encoding_stderr, encoding_stdout;
  61. private string username, domain;
  62. #if NET_2_0
  63. private SecureString password;
  64. #else
  65. private object password; // dummy
  66. #endif
  67. private bool load_user_profile;
  68. public ProcessStartInfo()
  69. {
  70. }
  71. public ProcessStartInfo(string filename)
  72. {
  73. this.filename = filename;
  74. }
  75. public ProcessStartInfo(string filename, string arguments)
  76. {
  77. this.filename = filename;
  78. this.arguments = arguments;
  79. }
  80. [RecommendedAsConfigurable (true), DefaultValue ("")]
  81. [TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts.AssemblySystem_Design)]
  82. [MonitoringDescription ("Command line agruments for this process.")]
  83. #if NET_2_0
  84. [NotifyParentPropertyAttribute (true)]
  85. #endif
  86. public string Arguments {
  87. get {
  88. return(arguments);
  89. }
  90. set {
  91. arguments = value;
  92. }
  93. }
  94. [DefaultValue (false)]
  95. [MonitoringDescription ("Start this process with a new window.")]
  96. #if NET_2_0
  97. [NotifyParentPropertyAttribute (true)]
  98. #endif
  99. public bool CreateNoWindow {
  100. get {
  101. return(create_no_window);
  102. }
  103. set {
  104. create_no_window = value;
  105. }
  106. }
  107. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content), DefaultValue (null)]
  108. [Editor ("System.Diagnostics.Design.StringDictionaryEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  109. [MonitoringDescription ("Environment variables used for this process.")]
  110. #if NET_2_0
  111. [NotifyParentPropertyAttribute (true)]
  112. #endif
  113. public StringDictionary EnvironmentVariables {
  114. get {
  115. if (envVars == null) {
  116. envVars = new ProcessStringDictionary ();
  117. foreach (DictionaryEntry entry in Environment.GetEnvironmentVariables ())
  118. envVars.Add ((string) entry.Key, (string) entry.Value);
  119. }
  120. return envVars;
  121. }
  122. }
  123. internal bool HaveEnvVars {
  124. get { return (envVars != null); }
  125. }
  126. [DefaultValue (false)]
  127. [MonitoringDescription ("Thread shows dialogboxes for errors.")]
  128. #if NET_2_0
  129. [NotifyParentPropertyAttribute (true)]
  130. #endif
  131. public bool ErrorDialog {
  132. get {
  133. return(error_dialog);
  134. }
  135. set {
  136. error_dialog = value;
  137. }
  138. }
  139. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden), Browsable (false)]
  140. public IntPtr ErrorDialogParentHandle {
  141. get {
  142. return(error_dialog_parent_handle);
  143. }
  144. set {
  145. error_dialog_parent_handle = value;
  146. }
  147. }
  148. [RecommendedAsConfigurable (true), DefaultValue ("")]
  149. [Editor ("System.Diagnostics.Design.StartFileNameEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  150. [TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts.AssemblySystem_Design)]
  151. [MonitoringDescription ("The name of the resource to start this process.")]
  152. #if NET_2_0
  153. [NotifyParentPropertyAttribute (true)]
  154. #endif
  155. public string FileName {
  156. get {
  157. return(filename);
  158. }
  159. set {
  160. filename = value;
  161. }
  162. }
  163. [DefaultValue (false)]
  164. [MonitoringDescription ("Errors of this process are redirected.")]
  165. #if NET_2_0
  166. [NotifyParentPropertyAttribute (true)]
  167. #endif
  168. public bool RedirectStandardError {
  169. get {
  170. return(redirect_standard_error);
  171. }
  172. set {
  173. redirect_standard_error = value;
  174. }
  175. }
  176. [DefaultValue (false)]
  177. [MonitoringDescription ("Standard input of this process is redirected.")]
  178. #if NET_2_0
  179. [NotifyParentPropertyAttribute (true)]
  180. #endif
  181. public bool RedirectStandardInput {
  182. get {
  183. return(redirect_standard_input);
  184. }
  185. set {
  186. redirect_standard_input = value;
  187. }
  188. }
  189. [DefaultValue (false)]
  190. [MonitoringDescription ("Standart output of this process is redirected.")]
  191. #if NET_2_0
  192. [NotifyParentPropertyAttribute (true)]
  193. #endif
  194. public bool RedirectStandardOutput {
  195. get {
  196. return(redirect_standard_output);
  197. }
  198. set {
  199. redirect_standard_output = value;
  200. }
  201. }
  202. #if NET_2_0
  203. public Encoding StandardErrorEncoding {
  204. get { return encoding_stderr; }
  205. set { encoding_stderr = value; }
  206. }
  207. public Encoding StandardOutputEncoding {
  208. get { return encoding_stdout; }
  209. set { encoding_stdout = value; }
  210. }
  211. #endif
  212. [DefaultValue (true)]
  213. [MonitoringDescription ("Use the shell to start this process.")]
  214. #if NET_2_0
  215. [NotifyParentPropertyAttribute (true)]
  216. #endif
  217. public bool UseShellExecute {
  218. get {
  219. return(use_shell_execute);
  220. }
  221. set {
  222. use_shell_execute = value;
  223. }
  224. }
  225. [DefaultValue ("")]
  226. [TypeConverter ("System.Diagnostics.Design.VerbConverter, " + Consts.AssemblySystem_Design)]
  227. [MonitoringDescription ("The verb to apply to a used document.")]
  228. #if NET_2_0
  229. [NotifyParentPropertyAttribute (true)]
  230. #endif
  231. public string Verb {
  232. get {
  233. return(verb);
  234. }
  235. set {
  236. verb = value;
  237. }
  238. }
  239. static readonly string [] empty = new string [0];
  240. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden), Browsable (false)]
  241. public string[] Verbs {
  242. get {
  243. string ext = filename == null | filename.Length == 0 ?
  244. null : Path.GetExtension (filename);
  245. if (ext == null)
  246. return empty;
  247. #if MOBILE
  248. return empty;
  249. #else
  250. switch (Environment.OSVersion.Platform) {
  251. case (PlatformID)4:
  252. case (PlatformID)6:
  253. case (PlatformID)128:
  254. return empty; // no verb on non-Windows
  255. default:
  256. RegistryKey rk = null, rk2 = null, rk3 = null;
  257. try {
  258. rk = Registry.ClassesRoot.OpenSubKey (ext);
  259. string k = rk != null ? rk.GetValue (null) as string : null;
  260. rk2 = k != null ? Registry.ClassesRoot.OpenSubKey (k) : null;
  261. rk3 = rk2 != null ? rk2.OpenSubKey ("shell") : null;
  262. return rk3 != null ? rk3.GetSubKeyNames () : null;
  263. } finally {
  264. if (rk3 != null)
  265. rk3.Close ();
  266. if (rk2 != null)
  267. rk2.Close ();
  268. if (rk != null)
  269. rk.Close ();
  270. }
  271. }
  272. #endif
  273. }
  274. }
  275. [DefaultValue (typeof (ProcessWindowStyle), "Normal")]
  276. [MonitoringDescription ("The window style used to start this process.")]
  277. #if NET_2_0
  278. [NotifyParentPropertyAttribute (true)]
  279. #endif
  280. public ProcessWindowStyle WindowStyle {
  281. get {
  282. return(window_style);
  283. }
  284. set {
  285. window_style = value;
  286. }
  287. }
  288. [RecommendedAsConfigurable (true), DefaultValue ("")]
  289. [Editor ("System.Diagnostics.Design.WorkingDirectoryEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  290. [TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts.AssemblySystem_Design)]
  291. [MonitoringDescription ("The initial directory for this process.")]
  292. #if NET_2_0
  293. [NotifyParentPropertyAttribute (true)]
  294. #endif
  295. public string WorkingDirectory {
  296. get {
  297. return(working_directory);
  298. }
  299. set {
  300. working_directory = value == null ? String.Empty : value;
  301. }
  302. }
  303. #if NET_2_0
  304. [NotifyParentPropertyAttribute (true)]
  305. public bool LoadUserProfile {
  306. get { return load_user_profile; }
  307. set { load_user_profile = value; }
  308. }
  309. [NotifyParentPropertyAttribute (true)]
  310. public string UserName {
  311. get { return username; }
  312. set { username = value; }
  313. }
  314. [NotifyParentPropertyAttribute (true)]
  315. public string Domain {
  316. get { return domain; }
  317. set { domain = value; }
  318. }
  319. public SecureString Password {
  320. get { return password; }
  321. set { password = value; }
  322. }
  323. #endif
  324. }
  325. }