Executing Exe  
Author Message
Atlantaazfinest





PostPosted: Visual C# General, Executing Exe Top

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

Visual C#3  
 
 
RMD





PostPosted: Visual C# General, Executing Exe Top

It should be as simple as:

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

 
 
Stefan Prodan





PostPosted: Visual C# General, Executing Exe Top

using System.Diagnostics;

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

For more details search the MSDN for Process class.



 
 
Atlantaazfinest





PostPosted: Visual C# General, Executing Exe Top

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


 
 
Stefan Prodan





PostPosted: Visual C# General, Executing Exe Top

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

 
 
Atlantaazfinest





PostPosted: Visual C# General, Executing Exe Top

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





PostPosted: Visual C# General, Executing Exe Top

Does anyone know how to embed the xbox.exe into my app so that the users cant access that file
 
 
Stefan Prodan





PostPosted: Visual C# General, Executing Exe Top

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

 
 
Atlantaazfinest





PostPosted: Visual C# General, Executing Exe Top

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


 
 
Atlantaazfinest





PostPosted: Visual C# General, Executing Exe Top

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
 
 
Badri Narayanan





PostPosted: Visual C# General, Executing Exe Top

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.


 
 
Atlantaazfinest





PostPosted: Visual C# General, Executing Exe Top

Do you have any good tutorials on this processs
 
 
Stefan Prodan





PostPosted: Visual C# General, Executing Exe Top

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


 
 
Atlantaazfinest





PostPosted: Visual C# General, Executing Exe Top

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





PostPosted: Visual C# General, Executing Exe Top

You call it like this:

RunEmbededExe("unpackedXBOXv2.exe");