Esempio n. 1
0
        private void frmMain_Load(object sender, EventArgs e)
        {
            RegistryKey retkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("software", true).CreateSubKey("mrwxk").CreateSubKey("mrwxk.ini"); //打开注册表项

            foreach (string strRNum in retkey.GetSubKeyNames())                                                                                      //判断是否注册
            {
                if (strRNum == Softreg.GetRNum())                                                                                                    //判断注册码是否相同
                {
                    this.Text       = "主窗体(已注册)";
                    button1.Enabled = false;
                    return;
                }
            }
            this.Text       = "主窗体(未注册)";
            button1.Enabled = true;
            MessageBox.Show("您现在使用的是试用版,该软件可以免费试用30次!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            Int32 tLong;

            try
            {
                //获取软件的已经使用次数
                tLong = (Int32)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\tryTimes", "UseTimes", 0);
                MessageBox.Show("感谢您已使用了" + tLong + "次", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch
            {
                //首次使用软件
                Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\tryTimes", "UseTimes", 0, RegistryValueKind.DWord);
                MessageBox.Show("欢迎新用户使用本软件", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            //获取软件已经使用次数
            tLong = (Int32)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\tryTimes", "UseTimes", 0);
            if (tLong < 30)
            {
                int Times = tLong + 1; //计算软件本次是第几次使用
                                       //将软件使用次数写入注册表
                Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\tryTimes", "UseTimes", Times);
            }
            else
            {
                MessageBox.Show("试用次数已到", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                Application.Exit();//退出应用程序
            }
        }
Esempio n. 2
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (textBox2.Text == "")//判断是否输入了注册码
     {
         MessageBox.Show("注册码输入不能为空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
     else
     {
         if (textBox2.Text.Equals(Softreg.GetRNum()))                                                                                                                             //判断注册码是否正确
         {
             RegistryKey retkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("software", true).CreateSubKey("mrwxk").CreateSubKey("mrwxk.ini").CreateSubKey(textBox2.Text); //打开注册表项,并创建一个子项
             retkey.SetValue("UserName", "mrsoft");                                                                                                                               //为新创建的注册表项设置值
             MessageBox.Show("注册成功,程序需要重新加载!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
             this.Hide();                                                                                                                                                         //隐藏当前窗体
             frmMain frmmain = new frmMain();                                                                                                                                     //实例化主窗体对象
             frmmain.Show();                                                                                                                                                      //显示主窗体
         }
         else
         {
             MessageBox.Show("注册码输入错误!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
Esempio n. 3
0
 private void frmRegister_Load(object sender, EventArgs e)
 {
     textBox1.Text = Softreg.GetRNum();
 }