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);//設置爲當前工作目錄的路徑

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章