How to check if the program is run on this computer for the first time? For example, to register a product in the database

  • which programm? - redL1ne
  • For example, write some value to the registry and check. Or create a file, only this is all unreliable methods. - Vladimir Martyanov
  • Is your program or third-party running? - MaximK

3 answers 3

When you first start you need to put down somewhere flag on the launch of this program. Then, with each subsequent launch, this flag can be checked. Where exactly to keep such a flag depends on your requirements and capabilities.

Here are some options:

  1. The key in the Windows registry.
  2. Create a file in the directory of your application in AppData.
  3. In the local database (if any).
  4. In the cloud (or on its publicly available servers), indicating the unique identifier of the machine.
  5. Hardware key (for example, encrypted USB stick).

Etc.

    There is no safe way (a malicious user can clean up behind the old installation), but the recommended way is to use the flag in Settings .

    • Can the flag be compiled into the assembly at startup? that is, directly change your executable code - Grundy
    • one
      @DimitryShevchenko: These paths are not reliable anyway. The user has control over his car. There is no sense to play against a malicious user, it is unethical, error-prone, discourages bona fide users and ultimately does not contribute to generating income from the sale of the program. - VladD
    • one
      @DimitryShevchenko: A malicious user will not pay anyway. Considering that you can force the user to pay with technical means while remaining within the bounds of the law and ethics is naive. - VladD
    • one
      @VladD, I agree with you in principle. But in this context, I discuss the problem purely from the technical side, since about ethics OP did not ask anything. - Dmitry Shevchenko
    • one
      @DimitryShevchenko: However, I think we have a consensus. - VladD

    for example, to register a product in a database

    Come up with a way (google way) to generate a unique machine ID, write it to the database and check for availability at startup.

    If the ID is not in the database - congratulations, this is the first launch.