I’m writing a program, which creates Windows service. So I need two .exe files – one for program, creating service and another for service itself. But I want to combine these two files into one. I have the following idea – open .exe file, which I want to pack (service application) in text editor and then copy its contents to some string. Then I need to create an empty .exe file in required directory and write the string to this file. But I suppose that’s not a good idea. What is the best way to solve my problem?
Thanks in advance.
For fun I wrote a “launcher” program that uses your method. It works, I tested it with zoomin.exe as the payload.
Once you’ve created the launcher executable, open both it and the payload file (zoomin.exe in my case) in Notepad++, and copy (using the Edit | Paste Special | Copy Binary Content and Paste Binary Content menu options).
You can find whereabouts in the launcher file the payload goes by searching in Notepad++ for “File Goes Here” and “End”.
Note, I do not recommend this in any way, it’s fiddly, error-prone and can break easily with different compiler settings. The way I have solved this in the past is, as already commented, to add the payload as a resource, which is much more maintainable.
Here’s an main() function for a self-installing service I wrote in C++ . In addition, the program allows the service to be run interactively.