可执行程序保存在触控机上。现在想调用。网上有很多方法,我照葫芦画瓢的使用。调用不了。
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的系统。
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的系统。
{ System.Diagnostics.Process.Start("萬年曆繁體.exe"); }
{ this.BeginInvoke(new Action(() => System.Diagnostics.Process.Start("萬年曆繁體.exe"))); }
process.StartInfo.FileName = "re.exe";
换成路径.
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();
string CurrentPath;
string filepath;
System.Diagnostics.Process p = new Process();
CurrentPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
filepath = (CurrentPath + "\\re.exe"); // System.Windows.Forms.MessageBox.Show("重启程序绝对路径为" + filepath);
p.StartInfo.FileName = filepath;
p.Start();这么写就行了。应该是跨平台的原因。使用的是WINCE5.0系统。
如果和被调用的 重启.exe 在同一台WinCe设备上,那么应该是路径不对需要注意的是:在WinCe设备上不支持Application.StartupPath,
要取得当前程序的路径,可以使用
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);