可能的重复:
使用 C# 加载 EXE 文件并从内存中运行它 https://stackoverflow.com/questions/3553875/load-an-exe-file-and-run-it-from-memory-using-c-sharp
我正在使用 WebClient 类从 Web 服务器下载 .exe。有没有一种方法可以运行 .exe 而无需先将其保存到磁盘?
为了完整起见,让我向您展示到目前为止我所拥有的内容。
这是我用来开始下载的代码:
WebClient webClient = new WebClient();
webClient.DownloadDataCompleted += new DownloadDataCompletedEventHandler(webClient_DownloadDataCompleted);
webClient.DownloadDataAsync(new Uri("http://www.somewebsite.com/calc.exe"));
在 (webClient_DownloadDataCompleted) 方法中,我只是从参数 e 中获取字节:
private void webClient_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
{
Byte[] downloadedData = e.Result;
// how to run this like a .exe?
}
谢谢。
If your .exe
是一个.NET程序,你可以加载程序集并运行其入口点 https://stackoverflow.com/q/5837958/458193.
否则,同时有办法做到这一点 https://stackoverflow.com/a/305319/458193,我看不到将文件保存在临时目录中并从那里运行它的问题,这要少得多。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)