对C Sharp.Net的怀疑 [英] Doubt in C Sharp.Net

查看:70
本文介绍了对C Sharp.Net的怀疑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI,

我是CSHARP的初学者!
请告诉我是否有一种方法可以将.exe(可执行文件)文件保存在资源文件中或任何地方,然后在任何地方运行?

例子
1.将名称为abcd.exe的文件添加到资源文件或脚本中的任何位置(请告诉我如何添加)

2.单击按钮将执行文件abcd.exe.

3.它必须以任何形式使用,因为Form1是父MDI.

请帮我 .给出更好解释的好的答复将非常有用.

感谢您的答复和尝试提供帮助的人!



I am a beginner to CSHARP!
Please tell me if there is a way to save an .exe (Executable) file in a resource file or any where and run it any where?

Example
1. A file with name abcd.exe is to be added to a resource file or any location in the script (Please tell me how to add also)

2. The file abcd.exe is executed on clicking to a button.

3. It must be usable in any form as Form1 is a parent MDI.

Please help me . A good reply with better explanation would be useful .

Thank you for the people who replyed and to the people who tried to help!!

推荐答案

您的问题尚不清楚,但是我可以解决.

是的,您可以将任何文件作为资源包含在部件中. (如果使用Visual Studio,则将其添加到项目中并作为Resource嵌入.我认为它与#Develop和其他IDE相似.在命令行上使用/res:abcd.exe.)

要运行文件,必须解压缩文件,将其保存到磁盘并进行处理.启动文件.
Your question is not clear, but I will have a go.

Yes, you can include any file as a resource in an assembly. (If using Visual Studio, add it to the project and Embad as Resource ... I think it''s similar in #Develop and probably other IDEs. On the command line use /res:abcd.exe.)

To run a file, you must unpack it, save it to disk and Process.Start it.
void RunFileFromResource(string name){
 Stream s = Assembly.GetExecutingAssembly.GetManifestResourceStream(name);
 string tempPath = Path.GetTempPath();
 FileStream fs = File.Open(tempPath + "/" + name, FileMode.Write);
 s.CopyTo(fs);
 fs.Close();
 s.Close();
 
 Process.Start(tempPath + "/" + name);
}



请记住,如果您使用的是VS,您将在所有资源上获得令人讨厌的名称空间前缀(据我所知,没有办法将其关闭).显然,您的程序集必须有权访问文件系统并被允许启动进程(这意味着完全信任),此功能才能正常工作.

您的观点3与其余问题没有任何意义.您可能要说的是,是否可以将 assembly 链接为资源,并在运行时从其中加载表单.尽管它确实是一件很奇怪的事情(如果您希望将其作为一个文件,则可以将所有类组合到一个程序集中).



Remember that if you''re in VS you will get the irritating namespace prefix on all your resources (as far as I am aware there is no way to turn this off). Your assembly must have access to the file system and be allowed to start processes (which means full trust) for this to work, obviously.

Your point 3 does not make sense with the rest of the question. What you may mean is whether it is possible to link an assembly as a resource, and load forms from within it at runtime. While it is, that is a strange thing to want to do (if you want it as one file you can just combine all the classes into one assembly).


为什么要隐藏可执行文件文件放在您的程序中?为什么不只是建立一个安装项目并正确安装呢?
Why are you hiding an executable file in your program? Why not just build a setup project and install it correctly?


不确定自己在做什么或为什么做.如果可执行文件是插件,则您要使用插件框架 [ ^ ]

您能否提供有关您要做什么的更多信息?
Not really sure about what you are doing or why. If the executables are plug-ins then you want to use a plug-in framework[^]

Can you provide more info on what you are trying to do?


这篇关于对C Sharp.Net的怀疑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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