user3571412
user3571412

Reputation: 215

Run exe file from FileStream

I'm trying to run an exe file through filestream , but nothing is happens when I call the command.

My code:

string filePath = AppDomain.CurrentDomain.BaseDirectory + "OUT\\WAMServer.exe";

// read the bytes from the application exe file
FileStream fs = new FileStream(filePath, FileMode.Open);
BinaryReader br = new BinaryReader(fs);
byte[] bin = br.ReadBytes(Convert.ToInt32(fs.Length));
fs.Close();
br.Close();

// load the bytes into Assembly
Assembly a = Assembly.Load(bin);

Anyone have tips or a solution?

Upvotes: 1

Views: 2236

Answers (2)

Chidchai
Chidchai

Reputation: 101

If you really want to start unmanaged application from byte array try this link https://stackoverflow.com/a/305319/820502

Upvotes: 1

ama1111
ama1111

Reputation: 579

Here's an example which runs an executable:

    static void Main(string[] args)
    {
        string filename = @"C:\windows\System32\notepad.exe";

        Process.Start(filename);
    }

Assembly.Load() won't run the executable, but instead loads it into the application domain, so Process.Start() might be what you're looking for.

Upvotes: 1

Related Questions