注册表限制软件使用次数

编程知识 更新时间:2023-05-01 23:02:01

软件程序入口加载即可。



public void UseTimesLimit()     //注册表限制软件使用次数
        {
            MessageBox.Show("您现在使用的是试用版,该软件可以免费试用30次!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            Int32 tLong;
            try
            {
                //获取软件的已经使用次数HKEY_CURRENT_USER  
                //tLong = (Int32)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\tryTimes", "UseTimes", 0);  
                tLong = (Int32)Registry.GetValue("HKEY_CURRENT_USER\\SOFTWARE\\tryTimes", "UseTimes", 0);
                MessageBox.Show("感谢您已使用了" + tLong + "次", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch
            {
                //首次使用软件  
                //Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\tryTimes", "UseTimes", 0, RegistryValueKind.DWord);  
                Registry.SetValue("HKEY_CURRENT_USER\\SOFTWARE\\tryTimes", "UseTimes", 0, RegistryValueKind.DWord);
                MessageBox.Show("欢迎新用户使用本软件", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
            //获取软件已经使用次数  
            //tLong = (Int32)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\tryTimes", "UseTimes", 0);  
            tLong = (Int32)Registry.GetValue("HKEY_CURRENT_USER\\SOFTWARE\\tryTimes", "UseTimes", 0);
            if (tLong < 30)
            {
                int Times = tLong + 1;//计算软件是第几次使用  
                //将软件使用次数写入注册表  
                //Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\tryTimes", "UseTimes", Times);  
                Registry.SetValue("HKEY_CURRENT_USER\\SOFTWARE\\tryTimes", "UseTimes", Times);
                //this.Close();//关闭本次操作窗口  

            }
            else
            {
                MessageBox.Show("对不起,您的免费试用次数已达上限,请通过正当途径获取注册码,进行注册使用!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                Application.Exit();//关闭整个应用程序 
            }
        }


更多推荐

注册表限制软件使用次数

本文发布于:2023-04-24 10:17:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/84be5063792f882352c735fad9ec480b.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:注册表   次数   软件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 100295文章数
  • 26025阅读数
  • 0评论数