//System.Diagnostics.Process process = new System.Diagnostics.Process();
//process.StartInfo.UseShellExecute = false;
//process.StartInfo.CreateNoWindow = true;
//process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
//process.StartInfo.RedirectStandardOutput = true;
//process.StartInfo.FileName = path;
//process.StartInfo.WorkingDirectory = Application.StartupPath;
//process.Start();System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo(path);
info.w.WorkingDirectory = path;
System.Diagnostics.Process.Start(info);//System.Diagnostics.Process.Start(path);
上面三种方法我試了都不行.
我的要求是: 相當於雙擊exe文件的動作.
我現在有一exe文件(是一個usb產品的測試程式).我雙擊它運行這個exe文件. 它會自動加载他目錄下的一個xml文件數據.
我現在用代碼啟動它.可就不能加载那個xml數據了
而我用自己c#生成的一個exe文件 上面三种方法都沒有問題..能讀取數據.
System.Diagnostics.ProcessStartInfo Info
= new System.Diagnostics.ProcessStartInfo();
// 设置外部程序名
Info.FileName = System.Configuration.ConfigurationSettings.AppSettings["FB_APPNAME"];
// 设置外部程序工作目录
Info.WorkingDirectory = System.Configuration.ConfigurationSettings.AppSettings["FB_WORKPATH"];
//声明一个程序类
System.Diagnostics.Process Proc;
try
{
// 启动外部程序
Proc = System.Diagnostics.Process.Start(Info);
}
catch(System.ComponentModel.Win32Exception err)
{
MessageBox.Show("系统找不到指定的程序文件。/n " + err,
"错误",
MessageBoxButtons.OK,
MessageBoxIcon.Error
);
}
FB_APPNAME
FB_WORKPATH
關鍵是你那個config文件里這兩個節點是什么內容.??
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WorkingDirectory = Application.StartupPath + @"\FormGen\";
p.Start();
p.StandardInput.WriteLine("FormGen.exe");
p.StandardInput.WriteLine("exit");
<add key="FB_APPNAME" value="D:\PointSoft\FBPos\FBReport.exe" />
<!-- F&B 工作目录. -->
<add key="FB_WORKPATH" value="D:\PointSoft\FBPos" />
System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo(path);
info.WorkingDirectory = Path.GetDirectoryName(path);
System.Diagnostics.Process.Start(info);
OK了