zoukankan      html  css  js  c++  java
  • 控制软件生命周期

       
       说明:添加引用Microsoft.win32,这主要是通过设置注册表来达到软件使用次数的控制。

       using Microsoft.win32; 
     
       private void Form1_Load(object sender, System.EventArgs e)
      {
       RegistryKey RootKey,RegKey; 

       //项名为:HKEY_CURRENT_USER\Software
       RootKey = Registry.CurrentUser.OpenSubKey ("Software",true);
       
       //打开子项:HKEY_CURRENT_USER\Software\MyRegDataApp
       if ((RegKey = RootKey.OpenSubKey ("MyRegDataApp",true)) == null)
       {
           RootKey.CreateSubKey("MyRegDataApp");//不存在,则创建子项
           RegKey = RootKey.OpenSubKey ("MyRegDataApp",true);
           RegKey.SetValue ("UseTime",(object)9); //创建键值,存储可使用次数
           MessageBox.Show ("您可以免费使用本软件10次!","感谢您首次使用");
           return;
       }

       try
       {
           object usetime = RegKey.GetValue ("UseTime");//读取键值,可使用次数
           MessageBox.Show ("你还可以使用本软件 :"+ usetime.ToString ()+ "次!","确认",MessageBoxButtons.OK ,MessageBoxIcon.Information );
           int newtime = Int32.Parse (usetime.ToString())-1;

           if (newtime<0)
           {
              if (MessageBox.Show ("继续使用,请购买本软件!","提示",MessageBoxButtons.OK ,MessageBoxIcon.Information )== DialogResult.OK )
              {
                 Application.Exit ();
              }
           }
           else
           {
              RegKey.SetValue ("UseTime",(object)newtime);//更新键值,可使用次数减1
           }
       }
       catch
       {
           RegKey.SetValue ("UseTime",(object)10); //创建键值,存储可使用次数
           MessageBox.Show ("您可以免费使用本软件10次!","感谢您首次使用");
           return;
       }   
      }

  • 相关阅读:
    http之100-continue
    WebHeaderCollection类
    python selenium登陆网易云音乐
    python爬虫多线程编程
    python使用unittest模块selenium访问斗鱼获取直播信息
    python之jsonpath的使用
    python 自定义函数
    Android 中万能的 BaseAdapter(Spinner,ListView,GridView) 的使用!
    Android UI设计
    Android杂谈--ListView之BaseAdapter的使用
  • 原文地址:https://www.cnblogs.com/winnxm/p/911079.html
Copyright © 2011-2022 走看看