如何将文件嵌入exe? [英] how can I embed a file into an exe?

查看:455
本文介绍了如何将文件嵌入exe?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将包含我的数据的文件嵌入到exe文件中,以便当用户调用它时,它将打开该文件,对其进行读取,采取措施,并且用户看不到该文件或对其没有任何访问权或知道它存在。我怎样才能做到这一点 ?诸如Molebox之类的文件打包器可以做到这一点,但要花很多钱。 VS2010可以做到这一点吗?但是我可能在Linux平台上也需要它。

I need to have a file containing my data embedded into an exe so when the users call it it will open the file, read it, take action and for the users to not see this file or have any access to it or know that it exists. How can I do this ? A file packer such as Molebox can do this but will cost quite a bit. Is there of doing this with VS2010 ? but I may also need this on a linux platform.

推荐答案

在项目中双击属性节点

单击资源,然后单击链接以创建资源文件

Click Resources, then click the link to create a resources file

点击添加资源,然后选择添加现有文件。这样会将文件添加到您的资源中。

Click "Add Resource" and select "Add an existing file". This adds the file to your resources.

文件被添加为Resources类的公共静态属性,可以通过给定的名称访问该文件。在示例中,我添加了一个名为 SampleConfiguration的xml文件。我可以通过以下代码在代码中访问它:

The file is added as a public static property of the Resources class that can be accessed by the name given it. in the example, I've added an xml file called "SampleConfiguration". I can access it within code by the following:

var fileString = ActivityLibrary1.Properties.Resources.SampleConfiguration;

其中 ActivityLibrary1 是其中的默认命名空间部件。由于该文件是文本文件,因此已添加为字符串资源。如果添加二进制文件,它将作为字节数组添加。如何处理字节数组中的文件是另一个问题...

Where ActivityLibrary1 is the default namespace of the assembly. As the file was a text file, it was added as a string resource. If you add a binary file, it will be added as a byte array. How to deal with files in byte arrays is another question...

这篇关于如何将文件嵌入exe?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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