日期:2014-05-17  浏览次数:21186 次

C#调用外部可执行程序
可执行程序保存在触控机上。现在想调用。网上有很多方法,我照葫芦画瓢的使用。调用不了。
using System.Diagnostics;  

 Process process = new Process();
 process.StartInfo.FileName = "重启.exe";
 process.StartInfo.Arguments = "";
 process.Start();

后来,在网上找了段程序:
 System.Diagnostics.Process process = new System.Diagnostics.Process();
  Process process = new Process();
  process.StartInfo.FileName = "re.exe";
  process.StartInfo.Arguments = "";
  try
  {
  process.Start();
  }
  catch (System.ComponentModel.Win32Exception e)
  {
  Console.WriteLine("系统找不到指定的程序文件。\r{0}", e);
  return;
  }  

程序会走到Console.WriteLine("系统找不到指定的程序文件。\r{0}", e);
接着触控机屏幕上会显示:
System.ComponentModel.Win32Exception: Win32Exception
  位于 System.Diagnostics.Process.StartWithShellExecuteEx() 
  位于 System.Diagnostics.Process.Start() 
  位于 System.Diagnostics.Process.Start(ProcessStartInfo startInfo) 
  位于 System.Diagnostics.Process.Start(String fileName) 
  位于 WindowsApplication1.DataBaseAdmin.saveFileDialog1_FileOk(Object sender, CancelEventArgs e) in \\192.168.15.102\tufn\tjlog\windowsapplication1\databaseadmin.cs:line 96 
  位于 System.Windows.Forms.FileDialog.OnFileOk(CancelEventArgs e) 
  位于 System.Windows.Forms.FileDialog.DoFileOk(IntPtr lpOFN) 
跟上面的信息差不多的一些东西。


不知道是不是路径的问题。比如,“重启.exe”保存在触控机 “我的设备(开机后显示桌面上的)-ResidentFlash(盘)-GUI(文件夹)”。路径该如何写。触控机是WINCE5.0的系统。


------解决方案--------------------
process.StartInfo.FileName = "re.exe";

换成具体路径试试
------解决方案--------------------
C# code
        private void 农历繁体ToolStripMenuItem_Click(object sender, EventArgs e)
        { System.Diagnostics.Process.Start("萬年曆繁體.exe"); }

------解决方案--------------------
应该是路径写的有问题,你可以尝试调用本地计算器,如果能调用。证明代码没有问题。
------解决方案--------------------
肯定是你路径的问题,
process.StartInfo.FileName = "re.exe";
换成路径.
------解决方案--------------------
process.StartInfo.FileName = "re.exe";你这是相对路径,看看文件存在吗,不行就换成绝对路径
------解决方案--------------------
指定全路径,从盘符开始
------解决方案--------------------
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = Application.StartupPath + "\\re.exe";//可执行程序在目录下
p.StartInfo.Arguments = "参数1 参数2";//传参用
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();