C# 启动带有参数的EXE文件

 public static  bool StartProcess(string filename, string[] args)
        {
            try
            {
                string s = "";
                foreach (string arg in args)
                {
                    s = s + arg + " ";
                }
                s = s.Trim();
                Process myprocess = new Process();
                ProcessStartInfo startInfo = new ProcessStartInfo(filename, s);
                myprocess.StartInfo = startInfo;
                myprocess.StartInfo.UseShellExecute = false;
                myprocess.Start();
                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("启动应用程序时出错!原因:" + ex.Message);
            }
            return false;
        }

如果在调用时还是提示缺少配置,可以加入如下代码,path为当前exe文件夹路径:

Directory.SetCurrentDirectory(path);//设置为当前工作目录的路径

猜你喜欢

转载自blog.csdn.net/qq_40433102/article/details/84873934