C#从资源运行exe [英] C# Run exe from resources

查看:91
本文介绍了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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆