From: sebastian nielsen on
If I have this code:
Dim fs As New System.IO.FileStream("C:\application.exe",
System.IO.FileMode.Open)
Dim br As New System.IO.BinaryReader(fs)
Dim data() as Byte
data = br.ReadBytes(Convert.ToInt32(fs.Length))
br.close()
fs.close()

Now data() contains the whole EXE in binary format, and I want to run
the binary data like the C:\application.exe was executed.

I tried with this:
Dim oAss As System.Reflection.Assembly
Dim meth As System.Reflection.MethodInfo
Dim obj As Object
oAss = System.Reflection.Assembly.Load(data)
meth = oAss.EntryPoint
obj = oAss.CreateInstance(meth.Name)
meth.Invoke(obj, Nothing)

but it stumbled on Load(data) that BadImageFormatException "It could
not read the file or collection 77824 bytes loaded from
WindowsApplication1, Version=1,0.0.0, Culture=neutral,
PublicKeyToken=null or one of its dependencys. A attempt to read in a
application with a invalid format was made"

Then I tried with another EXE, but the it stumbled on the Invoke(obj,
Nothing) that a incorrect number of parameters was supplied. The
debugger said that obj was "nothing", so apparently the
oAss.CreateInstance method failed.

I want it to work with any EXE, and the application should run the
content in the data() array like he EXE was launched itself.
I don't want to write the EXE to disk and exec it with the Shell()
method or some like that.
From: Patrice on
Use Process.Start instead tto run an exe file...

--
Patrice


"sebastian nielsen" <nielsen.sebastian(a)gmail.com> a �crit dans le message de
groupe de discussion :
fdb05669-e1e4-4997-858c-aa4fcea08a4d(a)34g2000hsf.googlegroups.com...
> If I have this code:
> Dim fs As New System.IO.FileStream("C:\application.exe",
> System.IO.FileMode.Open)
> Dim br As New System.IO.BinaryReader(fs)
> Dim data() as Byte
> data = br.ReadBytes(Convert.ToInt32(fs.Length))
> br.close()
> fs.close()
>
> Now data() contains the whole EXE in binary format, and I want to run
> the binary data like the C:\application.exe was executed.
>
> I tried with this:
> Dim oAss As System.Reflection.Assembly
> Dim meth As System.Reflection.MethodInfo
> Dim obj As Object
> oAss = System.Reflection.Assembly.Load(data)
> meth = oAss.EntryPoint
> obj = oAss.CreateInstance(meth.Name)
> meth.Invoke(obj, Nothing)
>
> but it stumbled on Load(data) that BadImageFormatException "It could
> not read the file or collection 77824 bytes loaded from
> WindowsApplication1, Version=1,0.0.0, Culture=neutral,
> PublicKeyToken=null or one of its dependencys. A attempt to read in a
> application with a invalid format was made"
>
> Then I tried with another EXE, but the it stumbled on the Invoke(obj,
> Nothing) that a incorrect number of parameters was supplied. The
> debugger said that obj was "nothing", so apparently the
> oAss.CreateInstance method failed.
>
> I want it to work with any EXE, and the application should run the
> content in the data() array like he EXE was launched itself.
> I don't want to write the EXE to disk and exec it with the Shell()
> method or some like that.


From: Cor Ligthert [MVP] on
In addition to Patrice

http://www.vb-tips.com/StartProcess.aspx

Cor

"Patrice" <http://www.chez.com/scribe/> schreef in bericht
news:e6JvrTP3IHA.1192(a)TK2MSFTNGP05.phx.gbl...
> Use Process.Start instead tto run an exe file...
>
> --
> Patrice
>
>
> "sebastian nielsen" <nielsen.sebastian(a)gmail.com> a �crit dans le message
> de groupe de discussion :
> fdb05669-e1e4-4997-858c-aa4fcea08a4d(a)34g2000hsf.googlegroups.com...
>> If I have this code:
>> Dim fs As New System.IO.FileStream("C:\application.exe",
>> System.IO.FileMode.Open)
>> Dim br As New System.IO.BinaryReader(fs)
>> Dim data() as Byte
>> data = br.ReadBytes(Convert.ToInt32(fs.Length))
>> br.close()
>> fs.close()
>>
>> Now data() contains the whole EXE in binary format, and I want to run
>> the binary data like the C:\application.exe was executed.
>>
>> I tried with this:
>> Dim oAss As System.Reflection.Assembly
>> Dim meth As System.Reflection.MethodInfo
>> Dim obj As Object
>> oAss = System.Reflection.Assembly.Load(data)
>> meth = oAss.EntryPoint
>> obj = oAss.CreateInstance(meth.Name)
>> meth.Invoke(obj, Nothing)
>>
>> but it stumbled on Load(data) that BadImageFormatException "It could
>> not read the file or collection 77824 bytes loaded from
>> WindowsApplication1, Version=1,0.0.0, Culture=neutral,
>> PublicKeyToken=null or one of its dependencys. A attempt to read in a
>> application with a invalid format was made"
>>
>> Then I tried with another EXE, but the it stumbled on the Invoke(obj,
>> Nothing) that a incorrect number of parameters was supplied. The
>> debugger said that obj was "nothing", so apparently the
>> oAss.CreateInstance method failed.
>>
>> I want it to work with any EXE, and the application should run the
>> content in the data() array like he EXE was launched itself.
>> I don't want to write the EXE to disk and exec it with the Shell()
>> method or some like that.
>
>


From: sebastian nielsen on
Yes, but what im doing, is that I have a encoder application, which
loads lets say c:\application.exe and makes a BASE64 string of it.
Then I put that BASE64 string as a constant into my application, and
now I want to run the BASE64 string by decoding it and then running
the contents in memory without writing the EXE to disk.

In other words, I want to hard-code a application into my application.
From: Cor Ligthert[MVP] on
Sebastian,

This is the difference between common people like most of us and artist like
you.

We just choose the most efficient methods, you see this probably as art.

However, art has to be unique, so very much success with your creation.

Cor

"sebastian nielsen" <nielsen.sebastian(a)gmail.com> schreef in bericht
news:0d50ce5f-4c40-4f85-9cd6-9bcbf51e57fe(a)r66g2000hsg.googlegroups.com...
> Yes, but what im doing, is that I have a encoder application, which
> loads lets say c:\application.exe and makes a BASE64 string of it.
> Then I put that BASE64 string as a constant into my application, and
> now I want to run the BASE64 string by decoding it and then running
> the contents in memory without writing the EXE to disk.
>
> In other words, I want to hard-code a application into my application.