C# 中运行exe程序

 private int runProcess(string fileName, string appParam)
        {
            int returnValue = -1;
            try
            {
                Process myProcess = new Process();
                ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(fileName, appParam);
                myProcessStartInfo.CreateNoWindow = true;
                myProcessStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                myProcess.StartInfo = myProcessStartInfo;
                myProcess.Start();

                while (!myProcess.HasExited)
                {
                    myProcess.WaitForExit();
                }

                returnValue = myProcess.ExitCode;
                myProcess.Dispose();
                myProcess.Close();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
            return returnValue;
        }

 1、启动*.exe程序

 
  System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); startInfo.Arguments = String.Format("{0} {1} {2}", columnStr, tempFilePath, "True"); startInfo.FileName = this.applicationPath + "\Excel.exe"; startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal; System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = startInfo;
   process.Start();   
   process.WaitForExit(); process.Close();

 2、调用外部程序

        private void CallOutProcess(string s文件名)
        {
            System.Diagnostics.ProcessStartInfo pinfo = new System.Diagnostics.ProcessStartInfo();
            pinfo.UseShellExecute = true;
            pinfo.FileName = s文件名;
            //启动进程
            System.Diagnostics.Process p = System.Diagnostics.Process.Start(pinfo);
        }
原文地址:https://www.cnblogs.com/shenchao/p/3556466.html