用C#怎么实现软件第一次启动的时候,把当前日期写入注册表,等下次启动的时候,判断软件的试用期是否到期

就像我们用的一般软件一样,30天后就不能使用了!这个安装后,第一次启动的时间如何让写入注册表啊!

1.取得服务器时间
2.加密服务器时间
3.启动时验证注册表是否存在该键(使用6中的方法验证)
4.若注册表不存在该键,将时间写入客户机注册表
try
{
RegistryKey rsg = null;
Registry.LocalMachine.CreateSubKey("SOFTWARE\\xxx");
rsg = Registry.LocalMachine.OpenSubKey("SOFTWARE\\xxx", true);
rsg.SetValue("键", 加密后的服务器时间);
rsg.Close();
err = "";
return true;
}catch(Exception ex)
{
//异常处理
}
5.若客户机存在该键,验证时间是否过期
6.验证时如下
try
{
RegistryKey rsg = null;
rsg = Registry.LocalMachine.OpenSubKey("SOFTWARE\\xxx", true);
if (rsg.GetValue("键") != null)
{
if (code.Equals(rsg.GetValue("键").ToString()))
{
rsg.Close();
}
rsg.Close();
}catch(Exception ex)
{
//异常处理
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-02-24
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
namespace BaiDuKnown
{
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
private RegistryKey rsgTime = null;
private void UserControl1_Load(object sender, EventArgs e)
{
rsgTime = Registry.LocalMachine.OpenSubKey("SOFTWARE\\YourSoftWareName", true);
string oldTime=rsgTime.GetValue("OldTime").ToString();
if (String.IsNullOrEmpty(oldTime))
{
Registry.LocalMachine.CreateSubKey("SOFTWARE\\YourSoftWareName");
rsgTime = Registry.LocalMachine.OpenSubKey("SOFTWARE\\YourSoftWareName", true);
rsgTime.SetValue("OldTime", DateTime.Now);
}
else
{
string dd = Convert.ToString(rsgTime.GetValue("OldTime"));
DateTime t1 = Convert.ToDateTime(dd);
DateTime t2 = DateTime.Now;
TimeSpan span = t1.Subtract(t2);

int days=Math.Abs(span.Days);
if (days <= 30)
{
MessageBox.Show("你的使用时间还剩" + span.TotalDays.ToString());
}
else
{
MessageBox.Show("你的软件已经过期");
}
}
}
}
}追问

这是是你自己写的吧!不是网上抄的吧!呵呵!

追答

是的

追问

very good ! 3ks !

还有就是你这个不能运行啊!你试过了吗!不知道怎么回事!
我的qq:470413137

本回答被提问者采纳
第2个回答  2011-02-28
恩,建议你看一看。。。using Microsoft.Win32;
RegistryKey

相关方面的知识,
无非就是打开相应的母键,然后,新建立一个键值,写入键值,
每次在软件启动的或是在FROM LOAD代码中读取,键值,然后和现在的时间 相比较...追问

恩!谢谢

第3个回答  2011-02-24
先新建一个注册表文件,里面写新建注册表项,每次开启程序的时候先检测,如果第一次执行,写入新注册表项,不是则检查
第4个回答  2011-03-05
oft.Win32; //声明///引用
RegistryKey reg;reg = Registry.ClassesRoot;

具体实现你百度一下就可以

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网