Click here to Skip to main content
15,906,333 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How would I set the date in the registry after installation and extract the date to see if it has expired after 30 days?

Here is my code:
Any better way to this as well?

/// <summary>
          /// The main entry point for the application.
          /// </summary>
          [STAThread]
          static void Main()
          {
               string dateInString = "04.10.2011"; //this date will be extracted from the registry when program was installed
               DateTime startDate = DateTime.Parse(dateInString);
               DateTime expiryDate = startDate.AddDays(30);
               if (DateTime.Now > expiryDate)
               {
                    DialogResult LicenseAgreement = MessageBox.Show("Do you acknowledge the EULA?" + "\n This message will appear every 30 days",
                    "End User License Agreement",
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Question,
                    MessageBoxDefaultButton.Button2);

                    if (LicenseAgreement == DialogResult.No)
                    {
                         MessageBox.Show("The program will exit now then");
                         Application.ExitThread();

                    }
                    else
                    {
                         RunProgram run = new RunProgram();
                    }
               }
               else
               {
                    RunProgram run = new RunProgram();
               }            
          }
          private class RunProgram
          {
               public RunProgram()
               {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new Form1());
               }
          }
          
     }
Posted

1 solution

 
Share this answer
 
Comments
Espen Harlinn 14-Apr-12 13:28pm    
5'ed!
Mehdi Gholam 14-Apr-12 13:35pm    
Thanks Espen!
VJ Reddy 15-Apr-12 6:39am    
Good links. 5!

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