读书人

c# 批改注册表代码

发布时间: 2012-08-19 21:09:48 作者: rapoo

c# 修改注册表代码
求修改注册表的简短的代码,并带有注释
例如我要把QQ应用程序写入注册表

[解决办法]

C# code
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();                //显示异常信息            } 

读书人网 >C#

热点推荐