C# Program Expiry Date: Setting an Expiration on Your App

This is more of a reference note for ourselves, but it’s a genuinely useful pattern if you’re building internal C# tools that need a simple built-in expiry date — for example, a utility you want to force people to re-download periodically rather than run indefinitely. The Code if (DateTime.Now >= new DateTime(2027, 12, 31)) { […]

C How To Set An Expiry Date On A Program
This is more of a reference note for ourselves, but it’s a genuinely useful pattern if you’re building internal C# tools that need a simple built-in expiry date — for example, a utility you want to force people to re-download periodically rather than run indefinitely.

The Code

if (DateTime.Now >= new DateTime(2027, 12, 31))
{
    MessageBox.Show("This program has expired. Please contact your administrator for an updated version.", "Program Expired", MessageBoxButtons.OK, MessageBoxIcon.Warning);
    Application.Exit();
}
Add this near the top of your Main() method (or your main form’s constructor/Load event) so the check runs before the rest of the program initialises. Application.Exit() ensures the program actually closes rather than just showing the message box and continuing.

Worth Knowing

This relies on the local system clock, so it’s trivially bypassed by anyone who sets their machine’s date backwards — fine for an internal tool where you’re relying on good faith and just want a gentle reminder to update, but not a real licensing/DRM mechanism if you need one that resists tampering.

A Couple of Practical Refinements

If this is going into anything beyond a quick personal script, two small changes are worth making. First, prefer DateTime.UtcNow over DateTime.Now — it removes the local time-zone as a variable, which matters if the same build is ever run by people in different regions or on a server. Second, consider a graduated warning rather than a hard cutoff: showing a “this build expires in 14 days” message starting a couple of weeks out gives people a chance to grab the update before they’re locked out mid-task, rather than hitting a dead stop with no notice. Neither of these changes the fundamental limitation above — a determined user can still wind the clock back — but they make the honest-use case noticeably friendlier. The pattern itself is unaffected by .NET version; it works identically whether you’re targeting classic .NET Framework (WinForms) or a modern .NET 8/9 WinForms or WPF project.
🛠️

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.