1
namespace Thermocoders_Licensing_System
{
class TrialTimeManager
{
    private string temp = "";

    public TrialTimeManager() { }

    public void SetNewDate()
    {
        DateTime newDate = DateTime.Now.AddDays(31);
        temp = newDate.ToLongDateString();
        StoreDate(temp);
    }

    public void Expired()
    {
        string d = "";
        using (Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\MyApp"))
        {
            d = (String)key.GetValue("Date");
        }
        DateTime now = DateTime.Parse(d);
        int day = (now.Subtract(DateTime.Now)).Days;
        if (day > 30) { }
        else if (0 < day && day <= 30)
        {
            string daysLeft = string.Format("{0} days more to expire", now.Subtract(DateTime.Now).Days);
            MessageBox.Show(daysLeft);

        }
        else if (day <= 0)
        {
            MessageBox.Show("Trial Expired Please Purchase The Product");
        }
    }

    public void StoreDate(string value)
    {
        try
        {
            using (Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(@"SOFTWARE\MyApp"))
            {
                key.SetValue("Date", value, Microsoft.Win32.RegistryValueKind.String);
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

    }

}

}

The code above keeps a track of number of days remaining for the trial period to expire.I want that after 30 days get over,the user should not be able to use the application and when he/she changes the system clock ,it should be detected and application usage should be denied.

Or Say in my application I have two buttons namely Try and register.I want that the try button be disabled after 30days or when the user changes the system clock,the user should not be able to use the application

If anyone has any other idea apart from making an entry in the registry please let me know as to how to make an entry into that file and keep it encrypted.

Thanks

leppie
  • 115,091
  • 17
  • 196
  • 297
user2614235
  • 161
  • 3
  • 7
  • 21
  • Yuriy I visited the link but couldn't find a satisfactory solution.Please give me the code to achieve the same. – user2614235 May 05 '14 at 10:07

0 Answers0