How to Run exe from memory or stream ?

hi
i embedd my exe in vs.net project as resource . now in run time i want to run my exe and don't save it in hard . how to do
my idea is load exe (in resource) to stream and run it . byt how to run it
my exe is win32 application ..
thanks..



Answer this question

How to Run exe from memory or stream ?

  • Said

    You can use something like this

    Program p = new Program();

    string[] arr=p.GetType().Assembly.GetManifestResourceNames();

    foreach (string s in arr)

    {

    Stream stream=p.GetType().Assembly.GetManifestResourceStream(s);

    byte[] asm = new byte[stream.Length];

    stream.Read(asm, 0, asm.Length);

    Console.WriteLine(asm.Length);

    Assembly a=Assembly.Load(asm);

    MethodInfo mi = a.EntryPoint;

    mi.Invoke(null, null);

    Console.WriteLine(s);

    }

    Console.ReadLine();

    provided your exe is in COFF



  • ilsandor

    hi,

    i'm not sure from this but give it a try

    1) right click your project name in solution explorer and select properties

    2)select resources Tab and from the top of this page select (Add resources/existing file) select your exe / open

    3) go to solution exploere / expand resources node right click your exe and select properties , from build Action select embeded resources

    4) in solution explorer right click your project again and select Add reference, go to browse tab , select your exe again

    now you can deal with your exe as you deal with other classes , for example MyexeNameSpace.Form1 f = new MyexeNameSpace.Form1();

    f.show();

    it will run the form but the exe will not appear in the output folder

    hope this helps



  • How to Run exe from memory or stream ?