I have a 3rd party EXE. I just need to run this from my C# application.
My prime target is to copyright that 3rd party executable from my C# file..
Is
One could write a simpler
private void ExtractResource(string resName, string fName) { object ob = Properties.Resources.ResourceManager.GetObject(resName, originalCulture); byte[] myResBytes = (byte[])ob; using (FileStream fsDst = new FileStream(fName, FileMode.CreateNew, FileAccess.Write)) { byte[] bytes = myResBytes; fsDst.Write(bytes, 0, bytes.Length); fsDst.Close(); fsDst.Dispose(); } }
right click on ur project the solution explorer then add existing item select executable file in dialog box then go to your exe path and add your exe in your project.. then if u wanna start your exe on button click event then write this code its simple easy ...
private void button_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("fire.EXE");
}
internal static byte[] SubExe {
get {
object obj = ResourceManager.GetObject("SubExe", resourceCulture);
return ((byte[])(obj));
}
}
add a method to access to your resource, which is also very simple, just add following code to your resource designer cs file
public static byte[] GetSubExe()
{
return SubExe;
}
In your main executable source code, add following to read resource and write it to a new file
string tempExeName = Path.Combine(Directory.GetCurrentDirectory(), "A3E5.exe");
using(FileStream fsDst = new FileStream(tempExeName,FileMode.CreateNew,FileAccess.Write))
{
byte[] bytes = Resource1.GetSubExe();
fsDst.Write(bytes, 0, bytes.Length);
}
Use process to run the new executable file