C# - How to Create Trial Version Windows Application
Make your application with trail version using Registry Key in C#
In previous articles I explained about ASP.Net - Encrypt and Decrypt Password, How to encrypt decrypt connection string in webconfig file?
If customers can use your app for free during a trial period you can design your app to exclude or limit some features during the trial period. In this article I will explain how to create a trail version windows applications, Make Your Application with Trial Version or C# window app a 30 day trail.
The best way to make windows application as trail software, is by setting the key in the registry. You can save a key in registry and in your application you can validate and check the validity of application. Find the source code below:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Security.Cryptography;
namespace CreateTrailWinApp
{
public partial class Form1 : Form
{
public
Form1()
{
InitializeComponent();
}
private
void Form1_Load(object
sender, EventArgs e)
{
try
{
CreateTrailfunctionality();
}
catch
(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private
void CreateTrailfunctionality()
{
try
{
Microsoft.Win32.RegistryKey EncryptedKey;
RSACryptoServiceProvider
crypto = new RSACryptoServiceProvider();
EncryptedKey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\EncryptedDate");
object
value = EncryptedKey.GetValue("EncryptedDate");
if
(value == null)
{
EncryptedKey =
Microsoft.Win32.Registry.CurrentUser.CreateSubKey(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\EncryptedDate");
string
keyvalue = DateTime.Now.ToString("dd-MMM-yyyy");
byte[]
messageBytes = Encoding.Unicode.GetBytes(keyvalue);
string
encryptedMessage = Convert.ToBase64String(messageBytes);
EncryptedKey.SetValue("EncryptedDate", encryptedMessage);
}
else
{
byte[]
encryptedMessage1 = Convert.FromBase64String(value.ToString());
string
key = System.Text.Encoding.Unicode.GetString(encryptedMessage1);
DateTime
date = Convert.ToDateTime(key);
MessageBox.Show(date.ToString("dd-MMM-yyyy"));
}
}
catch
(Exception e)
{ }
}
}
}
Please leave your comments, suggestions and queries about this post in the comment sections in order for me to improve my writing skills and to showcase more useful posts. Thanks for reading .. :)
C# - How to Create Trial Version Windows Application
Reviewed by Ravi Kumar
on
9:24 PM
Rating:
No comments: