All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
SQL子查询实例介绍_[SQL Server教程]
ASP.NET,2.0中使用样式、主题和皮肤_.net资料_编程技术
PHP实现同步远程Mysql_[PHP教程]
浅谈几个SQL的日志概念_[SQL,Server教程]
在ASP.NET,2.0中数据绑定的实现方法_.net资料_编程技术
创建ASP.NET 2.0用户控件
在Windows系统上安装PHP应用程序服务器_php资料_编程技术
在ASP.NET应用程序中上传文件_[Asp.Net教程]
浅谈PHP开发中MySQL数据库索引的经验_php资料_编程技术
把WebForm数据导出到Excel中_[Asp.Net教程]
Reading number is top 10 pictures
日本小萝莉2
No trading, no killing
两张抽象画
Li Zongrui hunting video screenshots2
随便发几张图
China's first snake village1
The money of more than 100 countries and regions8
Summer is most suitable for young people to travel in China9
Sora aoi possession of boudoir1
再来随便发几张
Download software ranking
实战黑客不求人
Unix video tutorial5
仙剑奇侠传98版歌曲
Sora aoi, the maid, students' uniforms
尖东毒玫瑰A
Boxer's Top ten classic battle3
Unix video tutorial13
DreamWeaver8
虚拟机5.5.3版
Tram sex maniac 2 (H) rar bag16
qq published in(发表于) 2014/7/11 9:23:59 Edit(编辑)
C#教程:将应用软件的使用次数写入注册表

C#教程:将应用软件的使用次数写入注册表

C#教程:将应用软件的使用次数写入注册表

将应用软件的使用次数写入注册表

在软件推广的时候,经常先让用户试用一定的次数,如果超过试用的次数,则不允许再试用本软件,这样的程序可以通过将软件的试用次数写入注册表来实现。下面的示例实现了如果用户使用本程序超过30次,则不再允许用户使用,并提示用户进行注册。运行结果如图1、图2、图3所示。



图1 试用主窗体



图2 使用次数提示窗体



图3 过期提示窗体

其设计原理是:首先判断在注册表指定的位置处是否建立了限制软件试用次数的数据项,如果该数据项存在,则使用Registry类的GetValue函数读取“使用次数”,然后用Registry类的SetValue函数设置“使用次数”为读取的“使用次数”加1;如果该数据项不存在,则使用Registry类的SetValue函数设置“使用次数”为1。代码如下:

private void button1_Click(object sender, EventArgs e)

{

try

{

Int32 tLong = (Int32)Registry.GetValue("HKEY_LOCAL_MACHINESOFTWAREmrsoft", "UserTimes", 0);

if (tLong < 30)

{

int Times = tLong + 1;

Registry.SetValue("HKEY_LOCAL_MACHINESOFTWAREmrsoft", "UserTimes", Times);

MessageBox.Show("这是您第" + Times + "次使用。");

}

else

{

MessageBox.Show("试用期已到请重新注册");

Application.Exit();//退出应用程序

}

}

catch

{

Registry.SetValue("HKEY_LOCAL_MACHINESOFTWAREmrsoft", "UserTimes",

First_Count, RegistryValueKind.DWord);

MessageBox.Show("感谢您第次使用本软件");

}

}

完整程序代码如下:

★ ★★★★FrmUserTime.cs窗体代码文件完整程序代码★★★★★

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using Microsoft.Win32;

namespace _7_02

{

public partial class FrmUserTime : Form

{

public FrmUserTime()

{

InitializeComponent();

}

private void FrmUserTime_Load(object sender, EventArgs e)

{

}

private int First_Count = 1;

private void button1_Click(object sender, EventArgs e)

{

try

{

Int32 tLong = (Int32)Registry.GetValue("HKEY_LOCAL_MACHINESOFTWAREmrsoft", "UserTimes", 0);

if (tLong < 30)

{

int Times = tLong + 1;

Registry.SetValue("HKEY_LOCAL_MACHINESOFTWAREmrsoft", "UserTimes", Times);

MessageBox.Show("这是您第" + Times + "次使用。");

}

else

{

MessageBox.Show("试用期以到请重新注册");

Application.Exit();

}

}

catch

{

Registry.SetValue("HKEY_LOCAL_MACHINESOFTWAREmrsoft", "UserTimes", First_Count, RegistryValueKind.DWord);

MessageBox.Show("感谢您第1次使用本软件");

}

}

//Const REG_SZ = 1



添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.