Click here to Skip to main content
15,890,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone,

i am trying to make make app expire after some days using the registry option, i have successfully written and read from registry, my issue is to check for expiration, from my code i assumed the user's first run is the 04/16/2017, i also assumed i want the user to run the application for one day, which supposed to expire on the 04/17/2017, meaning if the user tries to start the application after 04/17/2017 the if part should execute, but i am not really getting it right, the else part always execute, i will appreciate a better way of doing it. Thanks

What I have tried:

C#
<pre>regKey = Registry.CurrentUser.OpenSubKey("Systemfiles");//subkeyname
            if (regKey == null)
            {
                regKey = Registry.CurrentUser.CreateSubKey("Systemfiles");
                regKey.SetValue("tere", Encrypt("4/16/2017"));
            }
            else
            {
                regKey = Registry.CurrentUser.OpenSubKey("Systemfiles");//subkeyname
                string decryptDateValue = Decrypt(regKey.GetValue("tere").ToString());  //Keyname
                DateTime mainDate = Convert.ToDateTime(decryptDateValue);

                DateTime expiringDate = mainDate.AddDays(1);
                if (mainDate > expiringDate)
                {
                    expire = true;
                }
                else
                {
                    //Continue execution
                }
            }
Posted
Updated 20-Apr-17 23:06pm

1 solution

Read your instructions:
C#
DateTime expiringDate = mainDate.AddDays(1);
if (mainDate > expiringDate)
It is always false because expiringDate = mainDate + 1 day.

You have to compare expiringDate with the current date:
C#
if (DateTime.Now() > expiringDate)
 
Share this answer
 
Comments
Uwakpeter 21-Apr-17 5:07am    
i don't want to use the system date, any other way of doing it?
Jochen Arndt 21-Apr-17 5:30am    
Which date do you want to use instead of the current date?
Uwakpeter 21-Apr-17 5:53am    
the user might back date system date, then he/she will keep enjoying the application, to my, this is not a better approach to it.
Jochen Arndt 21-Apr-17 6:28am    
Yes he might. But this does not answer my question "Which date do you want to use instead of the current date".

You can't protect your application that way; especially when using the registry. There is always a method to bypass such "protections"; e.g. by deleting the registry value.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900