是否可以将bat文件嵌入.exe并将其与Process类一起使用? [英] Is it possible to embed a bat file in .exe and use it with the Process class?
问题描述
我创建了一个正在与Process一起使用的批处理文件.目前,我只让应用程序指向本地计算机上的目录.
I've created a batch file that is being used with a Process. I currently just have the application pointing to a directory on my local machine.
我不必将我的exe与该批处理捆绑在一起,而是希望将其作为资源嵌入,以便将其包含在exe中.批处理文件可以吗?
Rather than having to bundle my exe with this batch, I would like to just embed it as a resource so that it will be contained in the exe. Is this possible with a batch file?
ProcessStartInfo startInfo = new ProcessStartInfo()
startInfo.FileName = "c:\test\batchFile.bat";
// set up and execute batch file with various arguments
我已将批处理文件添加到我的解决方案中,并将其作为资源"添加到我的项目文件中.我不完全确定这是要走的路,还是在我的项目中如何访问它.
I've added the batch file to my solution, and added it as a "resource" to my project file. I'm not entirely sure this is the way to go, or how to access this in my project.
推荐答案
对于嵌入批处理文件-如果需要,您可以嵌入几乎所有内容...答案是肯定的:-)
As for embedding the batch file - you can embed just about anything if need be... the answer to this is yes :-)
关于如何使用嵌入式批处理文件-最简单的选择是从资源中读取文件(请参阅 http://msdn.microsoft.com/en-us/library/system.reflection.assembly.getmanifestresourcestream.aspx )并将其保存为真实文件-然后使用它.
As for how to use the embedded batch file - the easiest option is the read it from the resource (see http://msdn.microsoft.com/en-us/library/system.resources.resourcemanager.aspx and http://msdn.microsoft.com/en-us/library/system.reflection.assembly.getmanifestresourcestream.aspx) and save it as a real file - then use that.
如果您要嵌入.NET EXE/DLL,则可以在不将其保存为真实文件的情况下使用它...带有批处理文件,我怀疑您需要将其另存为真实文件.
IF you would embed a .NET EXE/DLL you could use that without saving it as a real file... with a batch file I suspect you will need to save it as a real file.
这篇关于是否可以将bat文件嵌入.exe并将其与Process类一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!