Reputation: 63
I want my program in Visual C# to allow the user to generate a portable .exe file to be run on another user's computer, with the portabe .exe receiving the values the first user inserted. I don`t want to use a configuration file or any other file to store the input values to be then read because I want the .exe to be a single file. I have the main and the second program (future portable executable) as different projects on the same solution. Is there a way to modify values of the portable .exe or does a new program needs to be compiled on the fly?
Upvotes: 0
Views: 2440
Reputation: 9108
You can typically append to an .exe
without breaking it and then read the data in upon execution.
Upvotes: 0
Reputation: 81483
To formally answer the question.
You can convert the assembly to IL, search and replace and recompile. However, if you are building this application, you should really consider the need and use case for such very thoroughly.
If you need just to modify the behavior of an application, you have a plethora of options.
If you are really tricky you "might" be able to track down the offset of an int and tweak it. However this seems very unreliable
Or if you really have your heart set on this, see the following and associated questions
Modify Emdeded String in C# compiled exe
Is it possible to Add/Remove/Change an embedded resource in .NET DLL?
Update from Ben Voigt Comments
Win32 Resources can be changed after being embedded in an EXE. .NET
System.Resources
can only be changed before embedding. C# applications are compatible with both kinds, but the distinction is very important The The necessary function is UpdateResource
Upvotes: 2