注册表限制软件使用次数

软件程序入口加载即可。



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();//关闭整个应用程序 
            }
        }


发布了9 篇原创文章 · 获赞 7 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/panjinliang066333/article/details/78657372