[急]WPF中一个程序中如何启动另外一个程序

starmoon1216 2011-07-05 11:36:18
小弟不才能力有限,各位大大可否给出接口方法。就是当一个程序启动了,这个程序后台就会启动另外一个程序。
...全文
607 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
燃烧土豆 2011-07-05
  • 打赏
  • 举报
回复
方法有几种
1.程序中打开
System.Diagnostics.Process.Start(程序路径);
例子

public void OpenRunPark()
{
try
{
//string path = @"E:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE\devenv.exe";
//string path = @"E:\Program Files\TTPlayer\TTPlayer.exe";
// string path = "C:\\Program Files\\Raymark\\Xpert-Central_live\\Main\\posisent.exe";
// System.Diagnostics.Process.Start(path);

System.Diagnostics.Process p = new System.Diagnostics.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.Start();
//string path = "start /D \"E:\\Program Files\\TTPlayer\\\" TTPlayer.exe";
string path = "start /D \"C:\\Program Files\\Raymark\\Xpert-Central_live\\Main\\\" posisent.exe";
//"E:\Program Files\TTPlayer\TTPlayer.exe"
//"C:\Program Files\Raymark\Xpert-Central_live\Main\posisent.exe"
p.StandardInput.WriteLine(path);
p.Close();
p.Dispose();

StreamWriter wt = File.AppendText(@"D:\xPertErrLog.txt");
wt.Write("打开应用程序成功!路径为"+path);
wt.WriteLine(File.GetLastWriteTime(@"D:\xPertErrLog.txt"));
wt.Close();
}
catch
{
StreamWriter wt = File.AppendText(@"D:\xPertErrLog.txt");
wt.Write("打开应用程序失败!请检查打开路径是否出错! ");
wt.WriteLine(File.GetLastWriteTime(@"D:\xPertErrLog.txt"));
wt.Close();
}

}

2.调用CMD打开

start /D "C:\Program Files\Raymark\Xpert-Central\Main\" posisent.exe



Dim p As New System.Diagnostics.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.Start()
Dim s As String = "start /D ""C:\Program Files\Raymark\Xpert-Central\Main\"" posisent.exe"
p.StandardInput.WriteLine(s)
p.Close()
p.Dispose()

3.注册后用协议打开
将下面的文件存储xx.reg


Code Snippet




REGEDIT4

[HKEY_CLASSES_ROOT\mxh]
"@"="URL:mxh Protocol"
@="URL:mxh Protocol"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\mxh\Shell]

[HKEY_CLASSES_ROOT\mxh\Shell\Open]

[HKEY_CLASSES_ROOT\mxh\Shell\Open\Command]
@="C:\\windows\\system32\\notepad.exe \"%1\""








然后注册,在浏览器里面输入:

mxh://



就可以打开记事本。
garfieldzf 2011-07-05
  • 打赏
  • 举报
回复
心蓝无敌 2011-07-05
  • 打赏
  • 举报
回复
Process.Start
zcxhappy1688 2011-07-05
  • 打赏
  • 举报
回复
BackgroundWorker

111,097

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧