0

Possible Duplicate:
how can i make my product as a trial version for 30 days?
Implementing a 30 day time trial

I am programming a trial application, which has a 30 day trial period,

in order to reserve the 30 day for user, I need to check for system time changes,

for example, if the user adds two days to the system Date and time, it will not harm the trial period, and it will remain 30 days, by subtracting the time changes from DateTime.now

I found a way by reading the events log, but I need an administrative permissions to do so, which are not available always.

Is there a way to get such info without needing administrative permissions?

Community
  • 1
  • 1
Abdallah Nasir
  • 607
  • 6
  • 33
  • 3
    Have you considered making the application "phone home" with the licence key, instead of relying on the system time? Or possibly using an NTP server? Also, have you considered how likely it is that such a user would actually buy your software anyway? (Think about how much effort you want to put into this compared with how much difference it will actually make in sales.) – Jon Skeet Nov 22 '12 at 07:33
  • Thanks @JonSkeet, but I think I cannot change the architecture by now after everything is ready but this bug. Thanks a lot :) – Abdallah Nasir Nov 22 '12 at 07:35
  • 2
    Again, how many sales do you think you'll actually lose due to this problem? How much effort is it *really* worth expending on this? – Jon Skeet Nov 22 '12 at 08:25
  • Duplicate of: [Implementing a 30 day time trial](http://stackoverflow.com/questions/2021088/), [how can i make my product as a trial version for 30 days?](http://stackoverflow.com/questions/1525378/), and [many many more that can be found searching for your question](https://www.google.com/search?q=license+30+days+trial+date+site%3Astackoverflow.com). The average answer is: don't do this at all, or keep it as simple as possible (i.e. store the install date in the register or a file). Your "security" will be broken by any user who really wants to. – CodeCaster Nov 22 '12 at 08:54
  • @CodeCaster , Thanks for replying, I am not writing for security, I am writing to give the user freedom of changing his time, like daylight saving, and other human factor errors, If I want to for security, I am sure your answer will be perfect. Thanks :) – Abdallah Nasir Nov 22 '12 at 09:58
  • That is not true. You are not writing this functionality for giving the user freedom, the user already has this freedom. On the contary, you're writing it to restrict the user in order to make limited use of your application. Any user with any technical knowledge will install your software in a VM, make a snapshot, and revert the VM to that snapshot after your program stops functioning. You cannot do anything against this other than [phoning home](http://en.wikipedia.org/wiki/Phoning_home) and you should not be wanting to rely on local date and time for this. – CodeCaster Nov 22 '12 at 10:01

2 Answers2

1

Instead of looking for the change in the system time, you could use a database that logs the date of the first day, and calculate the 30 time span after the first day.

So when the user opens the application for the first time, you will have to query your database to add the date of today(first time opening's date) and 30 days after today(first time opening's date)

To acquire the date of today and 30 days after, use the DateTime.Now function.

        string Today = DateTime.Now.Day + " - " + DateTime.Now.Month + " - " + DateTime.Now.Year;
        string End = DateTime.Now.AddDays(30).Day + " - " + DateTime.Now.AddDays(30).Month + " - " + DateTime.Now.AddDays(30).Year;

The downside to the above method is that if the user starts his application at say, year 2070. Then his application will not expire until year 2070.

So it is best if you get the date from an online source http://www.thetimenow.com/ instead of getting the date from the user's computer.

woodmon122
  • 45
  • 1
  • 5
-1

You can try by saving remaining days, install datetime and last check datetime. Make sure that both are set on install.

When user starts the program

if (lastCheck > DateTime.Now)
    {
         lastCheck = DateTime.Now;
    }
else
    {
         remainingDays = (DateTime.Now - lastCheck).TottalDays;
    }

Without further modification this will discourage user to modify date since it will lessen his remaining time when he sets date back. You can avoid this with little more code. I think its fairly simple yet efficient.

Edit: I might misunderstood the question.

I don't see any way to do that you want without code overkill. Most important thing is to protect your app from cracking/exloiting. If users want to play with the date, it's their loss.

If this was something to be expected because of application nature, it should have been dealt with before app was finished.

Hedrack
  • 694
  • 1
  • 6
  • 19
  • 1
    What if I change my system time to year 2020 prior to installing? Will this work? – One-One Nov 22 '12 at 08:19
  • DateTime has a time span from 00:00:00 (midnight), January 1, 0001 Anno Domini (Common Era) through 11:59:59 P.M., December 31, 9999 A.D. (C.E.) in the Gregorian calendar. It should be ok. – Hedrack Nov 22 '12 at 08:43