Executing Exe

Ok i added a exe file to my solutions explorer and i wanted to know what code i needed to execute the exe in my form 1

Answer this question

Executing Exe

  • darthziv

    using System.Diagnostics;

    Process proc = new Process();
    proc.StartInfo.FileName = "app.exe";
    proc.Start();

    For more details search the MSDN for Process class.



  • jonas k

    It should be as simple as:

    System.Diagnostics.Process process = new System.Diagnostics.Process();
    process.StartInfo.FileName = "Full Path to EXE";
    process.Start();

  • Michael Morris

    You call it like this:

    RunEmbededExe("unpackedXBOXv2.exe");



  • Neil Janabi

    You have to copy the unpackedXBOXv2.exe into the bin\Debug folder, next to Theme3.exe!

  • MJC2006

    i was reading up on it and i seen how to open a pic from the embedded resources but i cant seem to find anything on how to execute a .exe file that is a embedded resource
  • rekasnuh

    When you put app.exe i put the filename of the app in the solution explorer but i get a error that says system cant find the file.

    look here: http://yourserversolution.com/pro.JPG


  • Mikhail Ryzhinskiy

    Here it is:

    public static void RunEmbededExe(string exeName)
    {
      int read = 0;
      byte[] buffer = new byte[2048];
    
    
      Assembly asm = Assembly.GetExecutingAssembly();
      using (Stream stream = asm.GetManifestResourceStream(asm.GetName().Name + "." + exeName))
      {
        using (FileStream fs = new FileStream(Application.StartupPath + "\\" + exeName, FileMode.Create, FileAccess.Write))
        {
          using (BinaryWriter bw = new BinaryWriter(fs))
          {
            while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)
            {
              bw.Write(buffer, 0, read);
              bw.Flush();
            }
          }
        }
      }
      buffer = null;
    
      const int ERROR_FILE_NOT_FOUND = 2;
      const int ERROR_ACCESS_DENIED = 5;
    
      Process proc = new Process();
      try
      {
        proc.StartInfo.FileName = Application.StartupPath + "\\" + exeName;
        proc.StartInfo.CreateNoWindow = false;
        proc.Start();
        proc.WaitForExit();
      }
      catch (Win32Exception ex)
      {
        if (ex.NativeErrorCode == ERROR_FILE_NOT_FOUND)
        {
          MessageBox.Show(ex.Message + ". Check the path.");
        }
        else if (ex.NativeErrorCode == ERROR_ACCESS_DENIED)
        {
          MessageBox.Show(ex.Message + ".\n You do not have permission to run this file.");
        }
      }
    }
    


  • Malleswar

    is there anyway i can embed the exe into mine so that when i compile it users have to use mine
  • Halil_developer

    Does anyone know how to embed the xbox.exe into my app so that the users cant access that file
  • Chris Fink

    I gues xbox.exe is not written in managed code, so the only way to run it from your app is to embed it first and at runtime you'll copy from the resource to Windows TMP and run it from there.. then you delete it...

  • masmith

    Thanks Stefan in this code where it says exename is that where i add the name of the embedded resource
  • sabo

    Stefan Prodan wrote:
    I gues xbox.exe is not written in managed code, so the only way to run it from your app is to embed it first and at runtime you'll copy from the resource to Windows TMP and run it from there.. then you delete it...

    Do you have any tutorials on this or can you contact me on msn to help me if you have time . THANKS ALOT


  • EWoodruff

    Do you have any good tutorials on this processs
  • CalinMac

    As suggested by some other user, you need to copy that embedded resource to a temporary location (Windows Temp for eg). To create a file out of the embedded resource, you will use System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream (<the name of the exe resource). This gives you a System.IO.Stream object tha you read and write the content to a System.IO.FileStream object.


  • Executing Exe