2011-03-09 57 views
1

我发现需要从c#程序内启动WPF应用程序。我写了一个名为eBrowse的简单WPF浏览器作为练习。然后,我被要求将它添加到已经在使用的c#程序中。想要C#程序启动WPF应用程序

我试过System.Diagnostics.Process.Start(@"C:\eBrowse");但它没有奏效。

这是一个网站上找到另一种可能性:

myProcess.StartInfo.UseShellExecute = true; 
// You can start any process, HelloWorld is a do-nothing example. 
//myProcess.StartInfo.FileName = "C:\\HelloWorld.exe"; 
myProcess.StartInfo.FileName = @"C:\eBrowse"; 
myProcess.StartInfo.CreateNoWindow = true; 
myProcess.Start(); 
// This code assumes the process you are starting will terminate itself. 
// Given that is is started without a window so you cannot terminate it 
// on the desktop, it must terminate itself or you can do it programmatically 
// from this application using the Kill method. 

我想知道,如果它可能无法启动从C#中的WPF应用程序。任何想法都会很棒。

回答

1
using System.Diagnostics; 

Process myProc; 
myProc = Process.Start("calc.exe"); 

编译并在我的系统上运行visual studio 2008/10。

只需将calc.exe与完整路径交换到您的exe文件即可。

+0

谢谢大家的建议!不幸的是,WPF应用程序没有.exe,我认为这就是为什么我有这样的麻烦。我已经检查了多次,但没有办法从WPF获取.exe。 – 2011-03-10 14:02:38

+0

你用什么来制作exe文件?我使用visual studio 2010,我的WPF应用程序有一个.exe。 – clamchoda 2011-03-10 14:58:10

+0

你确定你有设置窗口来显示已知的文件扩展名吗? 在Windows资源管理器中,转至工具 - >文件夹选项 - >查看选项卡 - >确保“隐藏已知文件类型的扩展名”未选中。 – clamchoda 2011-03-10 15:00:25

0

这是否适合您? Winforms/WPF interoperability

+0

谢谢你的建议!我在#4上写过这个.exe是如何隐藏的,我不知道它在那里。我为此感到羞愧,但我想WPF让我处于一个循环之中。 – 2011-03-10 19:29:55

5

我想你没有指定你的EXE名称。 尝试以下操作:

myProcess.StartInfo.FileName = @"C:\eBrowse\yourEXeName.exe"; 
+0

谢谢你,你是对的,但我不知道它被埋在我的bin/Debug目录中。我有点尴尬,因为我的第一个stackoverflow问题。 – 2011-03-10 19:33:52

1

记得添加.exe扩展。 CreateNoWindow应该是false

+0

感谢您的建议!我在#4上写过这个.exe是如何隐藏的,我不知道它在那里。 – 2011-03-10 19:29:39