Search code examples
c#batch-fileembedded-resource

Is it possible to embed a bat file in .exe and use it with the Process class?


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.

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.


Solution

  • As for embedding the batch file - you can embed just about anything if need be... the answer to this is yes :-)

    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.

    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.