• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

简单介绍C#使用Process调用外部程序中所遇到的参数问题的代码示例

c# 搞代码 4年前 (2022-01-09) 29次浏览 已收录 0个评论

这篇文章主要介绍了C# 使用Process调用外部程序中所遇到的参数问题,需要的朋友可以参考下

在使用Process.Start 调用外部程序时,除了程序的地址之外,是可以传递参数的,Process.Start 也有多个重载;

//    // 摘要:    //   启动由包含进程启动信息(例如,要启动的进程的文件名)的参数指定的进程资源,并将该资源与新的 System.Diagnostics.Process    //   组件关联。    //    // 参数:    //  startInfo:    //   System.Diagnostics.ProcessStartInfo,包含用于启动进程的信息(包括文件名和任何命令行参数)。    //    // 返回结果:    //   与进程资源关联的新的 System.Diagnostics.Process 组件,或者如果没有启动进程资源(例如,如果重用了现有进程),则为 null。    //    // 异常:    //  System.InvalidOperationException:    //   在 startInfo 参数的 System.Diagnostics.ProcessStartInfo.FileName 属性中未指定任何文件名。-    //   或 - startInfo 参数的 System.Diagnostics.ProcessStartInfo.UseShellExecute 属性为    //   true,而 System.Diagnostics.ProcessStartInfo.RedirectStandardInput、System.Diagnostics.ProcessStartInfo.RedirectStandardOutput    //   或 System.Diagnostics.ProcessStartInfo.RedirectStandardError 属性也为 true。- 或    //   -startInfo 参数的 System.Diagnostics.ProcessStartInfo.UseShellExecute 属性为 true,而    //   System.Diagnostics.ProcessStartInfo.UserName 属性不为 null 或空,或者 System.Diagnostics.ProcessStartInfo.Password    //   属性不为 null。    //    //  System.ArgumentNullException:    //   startInfo 参数为 null。    //    //  System.ComponentModel.Win32Exception:    //   打开关联的文件时发生了错误。    //    //  System.ObjectDisposedException:    //   该进程对象已被释放。    public static Process Start(ProcessStartInfo startInfo);    //    // 摘要:    //   通过指定文档或应用程序文件的名称来启动进程资源,并将资源与新的 System.Diagnostics.Process 组件关联。    //    // 参数:    //  fileName:    //   要在进程中运行的文档或应用程序文件的名称。    //    // 返回结果:    //   与进程资源关联的新的 System.Diagnostics.Process 组件,或者如果没有启动进程资源(例如,如果重用了现有进程),则为 null。    //    // 异常:    //  System.ComponentModel.Win32Exception:    //   打开关联的文件时发生了错误。    //    //  System.ObjectDisposedException:    //   该进程对象已被释放。    //    //  System.IO.FileNotFoundException:    //   PATH 环境变量有包含引号的字符串。    public static Process Start(string fileName);    //    // 摘要:    //   通过指定应用程序的名称和一组命令行参数来启动一个进程资源,并将该资源与新的 System.Diagnostics.Process 组件相关联。    //   <b style="color:transparent">本文来源gao@!dai!ma.com搞$$代^@码网*</b> // 参数:    //  fileName:    //   要在该进程中运行的应用程序文件的名称。    //    //  arguments:    //   启动该进程时传递的命令行参数。    //    // 返回结果:    //   与该进程关联的新的 System.Diagnostics.Process 组件,或者如果没有启动进程资源(例如,如果重用了现有进程),则为 null。    //    // 异常:    //  System.InvalidOperationException:    //   fileName 或 arguments 参数为 null。    //    //  System.ComponentModel.Win32Exception:    //   打开关联的文件时发生了错误。    //    //  System.ObjectDisposedException:    //   该进程对象已被释放。    //    //  System.IO.FileNotFoundException:    //   PATH 环境变量有包含引号的字符串。    public static Process Start(string fileName, string arguments);    //    // 摘要:    //   通过指定应用程序的名称、用户名、密码和域来启动一个进程资源,并将该资源与新的 System.Diagnostics.Process 组件关联起来。    //    // 参数:    //  fileName:    //   要在该进程中运行的应用程序文件的名称。    //    //  userName:    //   启动进程时使用的用户名。    //    //  password:    //   一个 System.Security.SecureString,它包含启动进程时要使用的密码。    //    //  domain:    //   启动进程时要使用的域。    //    // 返回结果:    //   与进程资源关联的新的 System.Diagnostics.Process 组件,或者如果没有启动进程资源(例如,如果重用了现有进程),则为 null。    //    // 异常:    //  System.InvalidOperationException:    //   未指定文件名。    //    //  System.ComponentModel.Win32Exception:    //   fileName 不是可执行 (.exe) 文件。    //    //  System.ComponentModel.Win32Exception:    //   打开关联的文件时发生了错误。    //    //  System.ObjectDisposedException:    //   该进程对象已被释放。    public static Process Start(string fileName, string userName, SecureString password, string domain);    //    // 摘要:    //   通过指定应用程序的名称、一组命令行参数、用户名、密码和域来启动一个进程资源,并将该资源与新的 System.Diagnostics.Process    //   组件关联起来。    //    // 参数:    //  fileName:    //   要在该进程中运行的应用程序文件的名称。    //    //  arguments:    //   启动该进程时传递的命令行参数。    //    //  userName:    //   启动进程时要使用的用户名。    //    //  password:    //   一个 System.Security.SecureString,它包含启动进程时要使用的密码。    //    //  domain:    //   启动进程时要使用的域。    //    // 返回结果:    //   与进程资源关联的新的 System.Diagnostics.Process 组件,或者如果没有启动进程资源(例如,如果重用了现有进程),则为 null。    //    // 异常:    //  System.InvalidOperationException:    //   未指定文件名。    //    //  System.ComponentModel.Win32Exception:    //   fileName 不是可执行 (.exe) 文件。    //    //  System.ComponentModel.Win32Exception:    //   打开关联的文件时发生了错误。    //    //  System.ObjectDisposedException:    //   该进程对象已被释放。    public static Process Start(string fileName, string arguments, string userName, SecureString password, string domain);

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:简单介绍C#使用Process调用外部程序中所遇到的参数问题的代码示例
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址