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);
        }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM