Search code examples
c#registry

Reading and writing dates to the registry for trial version purposes


Here's what I want to do, I want to store the date the first time the program is installed and also store a date when was the program was last run. I want the code to check to see if it was more than 30 days since the installation so I can turn off features. I also want to check if the system date is less than the last opened date and if so write the installed date to 1/1/1901 to prevent the program from running.

Keeping in mind that this is not a consumer program but a business program I don't expect hackers to crack it, they may do but that is fine I simply want to give potential customers a reason to consider purchasing the program and the end of the trial will prompt this.

Q1: Does this sound reasonable?

Q2: How should I hide the fact these are dates so it's not easily identified and changed?

Many thanks Lee


Solution

  • The Microsoft.Win32 namespace is what you need. You will want to look at the two following classes: Registry and RegistryKey.

    You could store the hash code of your date within the registry key you will use.

    Except that I would neither place it in the registry. The AppData folder is a better place, in addition to your local installation folder. Perhaps will you want to to use binaries with the System.IO namespace so that you can write binary data. The BinaryWriter and BinaryReader classes are probably what you will need to do this.