0

I wanna assign value to variable after compiling . As example I wanna save computer information and date of starting and ... .

It saves this information into the .exe file and if user copy this file to another computer , Program will be automatically compare this information and current computer information (And disable to run).

Is it possible ? How can I save this data in .exe file without using database , or file or registry ?!

I am using C#

Thank u for read .

2 Answers2

1

Edit: And I found your answer here: Prevent EXE being copied to another PC - keep some info inside EXE file (e.g. some flag)

The problem with what you're thinking is that: - Even if your idea was even possible it would mean that before the .exe executes for the first time it would not be associated with any computer. So you would have an 'unlocked' version of the exe file. This also applies to the (correct) comment about modifying the values of a dll during runtime.

However even if it is possible to save variables/data to the exe file after compiling you should always have a different repository for such data (other file, registry, db etc.)

Community
  • 1
  • 1
gerodim
  • 131
  • 8
  • 1
    I wouldn't be too sure. I'd assume that you can store information in a Windows executable (e.g. in PE format), either "officially" as metadata or "unoffically" by abusing some unused data or such. I'm not sure you can open the program image of the running application on disk for writing though. (Although net executables actually start the net runtime so that they are not strictly "executing" themselves, but rather being executed.) One _could_ certainly open an unloaded dll and manipulate that, loading it only afterwards. Whether the OP really wants to do that is another question, of course. – Peter - Reinstate Monica May 21 '14 at 10:35
  • -1 - Please remove this answer, it's patently wrong, especially when it comes to .NET. Using reflection, a .NET binary can easily be modified and it's possible even to do so with unmanaged binaries (just harder). – xxbbcc May 30 '14 at 14:32
  • @xxbbcc The real point of this answer appears to be "*before the .exe executes for the first time it would not be associated with any computer. So you would have an 'unlocked' version of the exe file.*" [the implication being that the hypothetical pirate could just copy *that* onto another computer.] And that's true regardless of implementation technology. – zwol May 30 '14 at 16:17
  • @Zack You're right about that but this answer clearly states that it's impossible to do this, and that's wrong. (Whether it's useful to do that or not, that's up to opinion (it's not if you ask me)). If the poster rephrases the answer, I'll remove my -1. – xxbbcc May 30 '14 at 16:21
0

See this How To: Write User Settings at Run Time with C# and this Best practice to save application settings in a Windows Forms Application

Community
  • 1
  • 1
E.S
  • 536
  • 1
  • 9
  • 20
  • What is proposed here still saves the changes to a separate file. So if he copies the exe file to another computer all the changes will be lost. – gerodim May 21 '14 at 10:34