How to embed a .exe file in c# windows application
-
Define "embed"? In the most direct sense, no, you can't "embed" the .EXE in your app's resources and expect to run it directly from the resources. You'll have to copy the .EXE from the resources to a file on the hard drive, then run the .EXE from the file. The file will exist, and be locked, for the entire time that .EXE is running.
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
Define "embed"? In the most direct sense, no, you can't "embed" the .EXE in your app's resources and expect to run it directly from the resources. You'll have to copy the .EXE from the resources to a file on the hard drive, then run the .EXE from the file. The file will exist, and be locked, for the entire time that .EXE is running.
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007If that exe file is a .NET application you can load it in memory and run it
-
If that exe file is a .NET application you can load it in memory and run it
You can, but that's a big IF. Usually, when someone asks this question, it's because they want to add an .EXE that they don't have control over, like a command line utility or some other small Windows app.
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
Define "embed"? In the most direct sense, no, you can't "embed" the .EXE in your app's resources and expect to run it directly from the resources. You'll have to copy the .EXE from the resources to a file on the hard drive, then run the .EXE from the file. The file will exist, and be locked, for the entire time that .EXE is running.
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
I mean to use the .exe as a part of my windows applic, as when u embed .swf file in your applic interface, but here i need to meke the user use the .exe only as a part of my window, not as a separate window of it self.. Thanks for your reply..
It's possible, but not recommended as it can cause visual problems for the hosted app and is not what I would call a "production quality" solution. If this "embeded" app is a .NET-based .EXE, then you can run it out of the resources of your app. If not, then you must run it from an .EXE file on the hard drive. After it starts and puts up it's main form, you can call the Win32 API functions FindWindow and SetParent to set that window's parent to a window, like a Panel, in your application.
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
It's possible, but not recommended as it can cause visual problems for the hosted app and is not what I would call a "production quality" solution. If this "embeded" app is a .NET-based .EXE, then you can run it out of the resources of your app. If not, then you must run it from an .EXE file on the hard drive. After it starts and puts up it's main form, you can call the Win32 API functions FindWindow and SetParent to set that window's parent to a window, like a Panel, in your application.
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007the .exe is a macromedia flash .exe file, i tried to use the shockwave but it only runs .swf, i don't know if this makes a difference in the solution, and i hope if you could explain me more about finding the window and setting its parent if this is the only solution. Thanks again..;)
-
the .exe is a macromedia flash .exe file, i tried to use the shockwave but it only runs .swf, i don't know if this makes a difference in the solution, and i hope if you could explain me more about finding the window and setting its parent if this is the only solution. Thanks again..;)
Somehow, I just knew there was no good reason behind this... If you launch the .EXE using the Process class, you can easily get the window handle of the .EXE. Keep in mind, I have no idea if this is going to work for your ShockWave EXE! This code assumes there is a Panel control on your form called
myPanel
.// This sets up the P/Invoke to make a call to an external library, like Win32
[DllImport("user32.dll"), EntryPoint = "SetParent", SetLastError = true)]
private static extern IntPtr SetParent(IntPtr hwndChild, IntPtr hwndParent);... // Launch the .EXE... Process p = Process.Start("MyShockwave.EXE"); // Wait for the .EXE to create its window and start looking for input p.WaitForInputIdle(); // Assign the main window of the .EXE a new parent window SetParent(p.MainWindowHandle, myPanel.Handle); ...
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
Define "embed"? In the most direct sense, no, you can't "embed" the .EXE in your app's resources and expect to run it directly from the resources. You'll have to copy the .EXE from the resources to a file on the hard drive, then run the .EXE from the file. The file will exist, and be locked, for the entire time that .EXE is running.
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007- Create a new project, File.ReadAllBytes and then write them to a separate file ( .txt, .dat ) 2) Add this file to your resources. 3) Load it from the resource at runtime and save to a new file 4) Change extension to .exe OR 1) Change extension from .exe to .dat 2) Add as a resource 3) Load it from the resource at runtime and save to a new file 4) Change extension to .exe ?) What am I explaining at the moment? Are you trying to write a new kind of virus or just trying to make innocent programmers like me crazy? :) -- modified at 12:24 Monday 7th May, 2007
-
- Create a new project, File.ReadAllBytes and then write them to a separate file ( .txt, .dat ) 2) Add this file to your resources. 3) Load it from the resource at runtime and save to a new file 4) Change extension to .exe OR 1) Change extension from .exe to .dat 2) Add as a resource 3) Load it from the resource at runtime and save to a new file 4) Change extension to .exe ?) What am I explaining at the moment? Are you trying to write a new kind of virus or just trying to make innocent programmers like me crazy? :) -- modified at 12:24 Monday 7th May, 2007
Actually, his version of "embedding" was hosting the window of another .EXE in a form of his application.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007