0

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?

rkhb
  • 14,159
  • 7
  • 32
  • 60
user3571412
  • 105
  • 1
  • 9
  • Please be more specific what you mean by "nothing happens." Does the program stop running? Does `a` get set to `null`? Does an exception get raised? Does the program just continue executing after the `Assembly.Load` as if the `Load` never happened? – Raymond Chen Feb 11 '15 at 02:36
  • Simply click on the button with this code, and nothing happens – user3571412 Feb 11 '15 at 02:37
  • Have you verified that your path is correct? Try spitting it out to the console before loading. – Matt Clark Feb 11 '15 at 02:38
  • The path is correct. – user3571412 Feb 11 '15 at 02:41
  • What did you expect to happen? `Assembly.Load` does not run anything by itself (more or less, definitely not going to run any particular method)... Also it may be good idea to clarify whether your exe is managed or native... – Alexei Levenkov Feb 11 '15 at 03:17
  • Please be more specific than "nothing happens". Does execution continue as if the `Assembly.Load()` line were missing? Is that what you mean? Or do you mean that execution stops? – Raymond Chen Feb 11 '15 at 05:28

2 Answers2

1

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.

ama1111
  • 569
  • 3
  • 10
0

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

Community
  • 1
  • 1
Chidchai
  • 91
  • 6