如何在资源中运行而不提取任何位置C#请给我代码 [英] How to run in resources without extracting any location C# Please give me code
本文介绍了如何在资源中运行而不提取任何位置C#请给我代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
代码1:此代码提取并运行client.exe
Code 1 : This code extract and run client.exe
Assembly asm = Assembly.GetExecutingAssembly();<br />
string rootname = asm.GetName().Name.ToString();<br />
Stream strem = asm.GetManifestResourceStream(rootname + ".Resources." + "client.exe");<br />
<br />
BinaryReader br = new BinaryReader(strem);<br />
FileStream fs = new FileStream("client.exe",FileMode.OpenOrCreate);<br />
BinaryWriter bw = new BinaryWriter(fs);<br />
byte[] ba = new byte[strem.Length];<br />
strem.Read(ba, 0, ba.Length);<br />
bw.Write(ba);<br />
br.Close();<br />
bw.Close();<br />
<br />
Process p = new Process();<br />
p.StartInfo.FileName = "client.exe";<br />
p.Start();
-------------------------------------------------- ---------------------
代码2:此代码无效!
-----------------------------------------------------------------------
Code 2 : This code dont work !
//Get the current assembly<br />
Assembly assembly = Assembly.GetExecutingAssembly();<br />
<br />
//Get the assembly''s root name<br />
string rootName = assembly.GetName().Name;<br />
<br />
//Get the resource stream<br />
Stream resourceStream = assembly.GetManifestResourceStream(rootName + ".Resources." + "client.exe");<br />
<br />
//Verify the internal exe exists<br />
if (resourceStream == null)<br />
return;<br />
<br />
//Read the raw bytes of the resource<br />
byte[] resourcesBuffer = new byte[resourceStream.Length];<br />
<br />
resourceStream.Read(resourcesBuffer, 0, resourcesBuffer.Length);<br />
resourceStream.Close();<br />
<br />
//Load the bytes as an assembly<br />
Assembly exeAssembly = Assembly.Load(resourcesBuffer);<br />
<br />
//Execute the assembly<br />
exeAssembly.EntryPoint.Invoke(null, null); //no parameters
我想在没有提取资源的情况下运行client.exe我该怎么办!!!!!
i want to run client.exe in resources without extract how can i do !!!!!
推荐答案
嘿嘿,请回答!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!
" 碰碰"是不礼貌的-请不要这样做!
he heyy pls answer !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
''Bumping'' is rude - please do not do it!
这篇关于如何在资源中运行而不提取任何位置C#请给我代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文