2015-02-11 116 views
0

我试图通过文件流运行一个exe文件,但是当我调用该命令时没有任何事情发生。从FileStream运行exe文件

我的代码:

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); 

任何人有提示或解决方案?

+0

请再具体些,你的意思是“什么也没有发生。”程序是否停止运行? 'a'是否被设置为'null'?是否引发异常?程序是否在'Assembly.Load'之后继续执行,就好像'Load'从未发生过一样? – 2015-02-11 02:36:09

+0

只需用此代码点击按钮,什么都不会发生 – user3571412 2015-02-11 02:37:24

+0

您确认您的路径正确吗?加载前请尝试将其吐出到控制台。 – 2015-02-11 02:38:15

回答

1

下面是其运行的可执行一个例子:

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

     Process.Start(filename); 
    } 

Assembly.Load()将无法​​运行可执行文件,而是将其加载到应用程序域,所以Process.Start()可能是你在找什么。