ProcessUtil.cs 1.1 KB

1234567891011121314151617181920212223242526272829
  1. using System.Diagnostics;
  2. using System.Linq;
  3. namespace Update.Util
  4. {
  5. /// <summary>
  6. /// 进程工具
  7. /// </summary>
  8. public static class ProcessUtil
  9. {
  10. /// <summary>
  11. /// 运行指定程序,可指定命令行参数
  12. /// </summary>
  13. /// <param name="fileName">要运行的程序路径</param>
  14. /// <param name="args">命令行参数数组</param>
  15. /// <returns>如果启动了进程资源,则为 true;如果没有启动新的进程资源(例如,如果重用了现有进程),则为 false。</returns>
  16. public static bool Start(string fileName, params string[] args)
  17. {
  18. Process process = new Process();
  19. process.StartInfo.FileName = fileName;
  20. if (args != null)
  21. process.StartInfo.Arguments = string.Join(" ", args.Select(arg => "\"" + arg + "\""));
  22. process.StartInfo.UseShellExecute = false;
  23. process.StartInfo.RedirectStandardOutput = true;
  24. process.StartInfo.CreateNoWindow = true;
  25. return process.Start();
  26. }
  27. }
  28. }