最近工作比较忙,没什么时间来博客 . 如今工作接近尾声, 现在总结一些以后需要用到的功能.
产品在正式交付给客户之前需要交付一个试用版本,可以使用一百次.
我想到的实现办法很简单,在注册表写如一个数据,每次使用数据就+1 . 代码如下:
View Code
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Win32; namespace ConsoleApplication4 { class Program { static void Main(string[] args) { if (Flag()) { Console.WriteLine("成功"); } else { Console.WriteLine("试用期已过"); } } /// <summary> /// 写入注册表 /// </summary> /// <param name="Count"></param> private static void SetRegedit(int Count) { RegistryKey Huser = Registry.CurrentUser; RegistryKey zcb = Huser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\System\Service\Number", true); zcb.SetValue("ShellValue", Count); } /// <summary> /// 读取注册表 /// </summary> /// <returns></returns> private static int ReadRegedit() { int count = 0; try { RegistryKey Huser = Registry.CurrentUser; RegistryKey zcb = Huser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\System\Service\Number", true); count = Convert.ToInt32(zcb.GetValue("ShellValue")); SetRegedit(count + 1); } catch { CreateRegedit(); } SetRegedit(count + 1); return count; } /// <summary> /// 判断试用期 /// </summary> /// <returns></returns> public static bool Flag() { int count = ReadRegedit(); if (count <= 2) { return true; } return false; } /// <summary> /// 创建注册列表 /// </summary> private static void CreateRegedit() { RegistryKey Huser = Registry.CurrentUser; RegistryKey zcb = Huser.OpenSubKey(@"Software\Microsoft\Windows\", true); RegistryKey ssub = zcb.CreateSubKey(@"CurrentVersion\Policies\System\Service\Number", RegistryKeyPermissionCheck.ReadWriteSubTree); ssub.SetValue("ShellValue", 0); } } }
当然这是最简单的,你也可以设计试用时间的长短, 插入一个时间也行. 但是值得注意的是, 你所插入的注册表目录需要很隐蔽.不容易被找到.