软件添加注册功能

        软件添加注册功能: 给用户一个界面输入Key(注:此Key是我用别的工具加密生成), 直接写到用户电脑的注册表中。软件每次开启,都会对比注册表中的时间与当前时间,以此判断软件是否过期,

 

 代码如下:

View Code

 

/*写入注册表*/
public static void WriteSetting(string Section, string Key, string Setting) // name = key value=setting Section= path
{
string text1 = Section;
RegistryKey key1 = Registry.CurrentUser.CreateSubKey("Software\\efwplusServer\\cdkey"); // .LocalMachine.CreateSubKey("Software\\mytest");
if (key1 == null)
{
return;
}
try
{
key1.SetValue(Key, Setting);
}
catch (Exception exception1) { return; } finally { key1.Close(); } }

 

 

/// <summary>
/// 读取注册表
/// </summary>
/// <param name="Section"></param>
/// <param name="Key"></param>
/// <param name="Default"></param>
/// <returns></returns>
public static string ReadSetting(string Section, string Key, string Default)
{
RegistryKey registryKey = Registry.CurrentUser.OpenSubKey("Software\\MyServer\\cdkey");
if (registryKey != null)
{
object objValue = registryKey.GetValue(Key, Default);

if (objValue != null)
{
Default = Encryption.DisEncryPW(objValue.ToString(), key2); } registryKey.Close(); } return Default; }
public static string InitRegedit(out string expireDate)
        {
            string res = "";
            expireDate = "";
            /*检查注册表 BFEBFBFF000206A7-20190112*/
            string SericalNumber = ReadSetting("", "SerialNumber", "-1");   
            if (SericalNumber == "-1")
            {
                res = "软件尚未注册,请注册软件!"; } /* 比较CPUid */ string CpuId =SericalNumber.Split('-')[0]; string CpuIdThis = GetCpuId(); if (CpuId != CpuIdThis) { res = "注册机器与本机不一致,请联系管理员!"; } /* 比较时间 */ string NowDate = DateTime.Now.ToString("yyyyMMdd"); string EndDate = SericalNumber.Split('-')[1]; if (Convert.ToInt32(EndDate) - Convert.ToInt32(NowDate) < 0) { res = "软件试用已到期!"; } DateTime dt = DateTime.ParseExact(EndDate, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture); expireDate = dt.ToString("yyyy年MM月dd日"); return res; }
 
  
http://www.cnblogs.com/kakake/p/3938262.html
QQ:273999072 框架学习中

 

转载于:https://www.cnblogs.com/chuangjie1988/p/6655744.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值