Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more: , +
I want to execute an exe within a wpf application. i have used the following code:
C#
private void tabControl1_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
{
    if (tabControl1.SelectedIndex == 4)
    {
        Process p = new Process();
        p.StartInfo = new ProcessStartInfo("C:\\Program Files\\WordWeb\\wweb32.exe");
        // p.StartInfo = new ProcessStartInfo("C:\\Program Files\\WordWeb\\wweb32.exe", this.Arrange(rectangledict));
        //p.WaitForInputIdle();
        p.Start();
    }
}


I am able to load the the exe. But the exe opens in a different window. I want the exe to run in the same window. After reading some blogs, I got to know to implement the parent child relationship. Can any body help me to do the same? I am using VS 2008 SP1.
Posted
Updated 5-May-11 1:45am
v2

If the application you want to start is a Console application and you want the output to be printed into your form, then this will help: How to redirect Standard Input/Output of an application[^]

Otherwise, I don't understand "I want the exe to run in the same window"...
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 5-May-11 18:02pm    
Correct but only if the guest application writes in console. My 5, as we don't know exactly what is that. May be that's not it.
Please see my solution.
--SA
You can't run another application in your app's window - well, technically you can, but only if your application is a shell for the OS (kinda like the fact that the Windows desktop is actually Windows Explorer running in full-screen mode, or a VM client that runs a completely different OS).
 
Share this answer
 
Comments
aditya behara 5-May-11 7:54am    
can you elaborate this Solution by giving an example or code snippet.
Sergey Alexandrovich Kryukov 5-May-11 17:59pm    
See my solution and the reference to my past solution.
--SA
Sergey Alexandrovich Kryukov 5-May-11 18:00pm    
My 5. There are other approaches, see my solution.
Good results are not guaranteed.
--SA
#realJSOP 5-May-11 18:02pm    
If you want guarantees, you should buy kitchen appliances. :)
Sergey Alexandrovich Kryukov 5-May-11 22:52pm    
How long-term factory warranty would you personally provide if you were selling kitchen appliances?
--SA
If your host application just writes to the console, please use solution provided by Olivier.

What if it does not?

You would better avoid it, but if you really want it, there are some opportunities I explained in my past Solution:

Is it possible to run a window form application from another running window form application[^].

With WPF, this is somewhat more difficult than with System.Windows.Forms. You may need to host a System.Windows.Forms.Control in your WPF application, see:
http://msdn.microsoft.com/en-us/library/system.windows.forms.integration.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.integration.windowsformshost.aspx[^],
http://nayyeri.net/host-windows-forms-controls-in-wpf[^].

Again, it depends on how your guest application works. In the general case the result is not guaranteed.

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900