C# How to set an expiry date on a program

This is more of a post for our reference but we thought our visitors might be able to make use of it as well so here it is. If you want to build a program in C# that upon startup checks the date and if that date has passed throws an error and will not […]

C How To Set An Expiry Date On A Program
This is more of a post for our reference but we thought our visitors might be able to make use of it as well so here it is. If you want to build a program in C# that upon startup checks the date and if that date has passed throws an error and will not load the program, then you should add this code to your program.cs class.
if (DateTime.Now >= new DateTime(2015, 12, 31))
{
MessageBox.Show("Program Expired - Contact Administrator", "Program Name", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return;
}
To break down this code, you will see that it looks at the date and time as is now, then it states a date and time of when the program will expire – so this is the date you set and should change to your own requirements. You will also see that we have put in a message box here, but you can put in whatever you want here.

Feedback

If you have any questions or comments on this, please feel free to use our comments system below.
🛠️

Gear We Recommend

A few general tech accessories worth having alongside this.

Browse our General Tech Accessories picks on Amazon

As an Amazon Associate, TechyGeeksHome earns from qualifying purchases.


Discover more from TechyGeeksHome

Subscribe to get the latest posts sent to your email.

Andrew Armstrong

Andrew Armstrong is a UK-based IT professional with 26+ years of hands-on experience in Windows, Windows Server, SCCM/ConfigMgr, Active Directory, PowerShell, and enterprise infrastructure.

He founded TechyGeeksHome in 2010 and has published over 1,500 practical guides covering real-world IT problems and solutions. When not solving IT problems,

Andrew develops free Windows utilities including Ultimate Settings Panel, which has been downloaded over 850,000 times.