Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to embed a .exe file in c# windows application

How to embed a .exe file in c# windows application

Scheduled Pinned Locked Moved C#
csharptutorial
10 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    r_jaz
    wrote on last edited by
    #1

    Hi, How to embed a .exe file in c# windows application Thanks,

    D 1 Reply Last reply
    0
    • R r_jaz

      Hi, How to embed a .exe file in c# windows application Thanks,

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      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

      G R A 3 Replies Last reply
      0
      • D Dave Kreskowiak

        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

        G Offline
        G Offline
        Giorgi Dalakishvili
        wrote on last edited by
        #3

        If that exe file is a .NET application you can load it in memory and run it

        D 1 Reply Last reply
        0
        • G Giorgi Dalakishvili

          If that exe file is a .NET application you can load it in memory and run it

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • D Dave Kreskowiak

            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

            R Offline
            R Offline
            r_jaz
            wrote on last edited by
            #5

            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..

            D 1 Reply Last reply
            0
            • R r_jaz

              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..

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              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

              R 1 Reply Last reply
              0
              • D Dave Kreskowiak

                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

                R Offline
                R Offline
                r_jaz
                wrote on last edited by
                #7

                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..;)

                D 1 Reply Last reply
                0
                • R r_jaz

                  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..;)

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #8

                  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

                  1 Reply Last reply
                  0
                  • D Dave Kreskowiak

                    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

                    A Offline
                    A Offline
                    AFSEKI
                    wrote on last edited by
                    #9
                    1. 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
                    D 1 Reply Last reply
                    0
                    • A AFSEKI
                      1. 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
                      D Offline
                      D Offline
                      Dave Kreskowiak
                      wrote on last edited by
                      #10

                      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

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups