日期:2014-05-18 浏览次数:21139 次
try //可能有异常,放在try块中
{
RegistryKey rsg = null; //声明变量
rsg = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft", true); //true表可修改
if (rsg.GetValue("XXX") != null) //如果值不为空
{
count = int.Parse(rsg.GetValue("XXX").ToString());
rsg.SetValue("XXX", (count + 1).ToString());//创建键值//读取值
}
else
{
rsg.SetValue("XXX", (count + 1).ToString());//创建键值
}
rsg.Close(); //关闭
}
catch (Exception ex) //捕获异常
{
MessageBox.Show("读取写入注册表错误!");
Application.Exit();
//显示异常信息
}