C#从资源运行exe

编程入门 行业动态 更新时间:2024-10-11 11:22:02
本文介绍了C#从资源运行exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是我的代码

this is my code

static void Main(string[] args) { if (args.Length >= 2 && args[0].ToLower() == "/launch") { Assembly.Load((byte[])new ResourceManager(typeof(Properties.Resources)).GetObject(args[1])).EntryPoint.Invoke(null, null); } else { Process.Start(Assembly.GetExecutingAssembly().CodeBase, "/launch NameOfResource"); }

它的意思是运行我放在recouces文件中的程序,但是它似乎没有用,它什么也没做,我想知道是否有人可以帮助我解决这个问题?

its meant to run the program i dropped in the recouces file, but it dosen''t seem to work, it dosen''t do anything, i was wondering if anyone can help me with this?

推荐答案

变量:
  • 将同级exe部署到启动器中,然后将其作为进程启动.
  • 将其加载到应用程序域中并执行 (但要了解的不只是一个班轮电话: 序列化,应用程序域边界上的异常处理,安全性 设置,...).
  • Variants:
    • Deploy the exe as sibling to your launcher and start it as a process.
    • Load it into an app domain and execute (but there is more to know about that than only a single liner call: serialization, exception handling over app domain boundaries, security settings, ...).
    • 没有道德的程序员应该这样做,但这是一种方法.这是非法的,因为您不关心用户的权利或特权或隐私. No ethical programmer should do this, but this is a way. This is illegal as you are not concerned about user''s rights or previleges or privacy. Assembly asm=null; using (Stream manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("yourresourceName")) { if (manifestResourceStream != null) { try { byte[] numArray = new byte[manifestResourceStream.Length]; manifestResourceStream.Read(numArray, 0, numArray.Length); asm = Assembly.Load(numArray); } catch { } } } if(asm !=null) { var entryPoint = asm.EntryPoint; var commandArgs = new string[1]; var returnValue = entryPoint.Invoke(null, commandArgs); }

更多推荐

C#从资源运行exe

本文发布于:2023-11-13 06:01:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1583640.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:资源   exe

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!