读写注册表

content
"/// <summary>
        /// 读取注册表键值
        
/// </summary>

        public static string ReadRegistryKey(string name)
        
{
            Microsoft.Win32.RegistryKey reg 
= Microsoft.Win32.Registry.CurrentUser;
            
string path=""Software\\"" + Application.ProductName;

            
if (reg.OpenSubKey(path) == null)
                reg.CreateSubKey(path);

            reg 
= reg.OpenSubKey(path, true);

            
string str;
            
if (reg.GetValue(name) == null)
                str
="""";
            
else
                str 
= reg.GetValue(name).ToString();

            reg.Close();
            
return str;
        }


        
/// <summary>
        
/// 设置注册表键值
        
/// </summary>

        public static void SetRegistryKey(string name, string Value)
        
{
            Microsoft.Win32.RegistryKey reg 
= Microsoft.Win32.Registry.CurrentUser;
            
string path=""Software\\"" + Application.ProductName;

            
if (reg.OpenSubKey(path) == null)
                reg.CreateSubKey(path);

            reg
=reg.OpenSubKey(path,true);

            reg.SetValue(name, Value);
            reg.Close();
        }


        
/// <summary>
        
/// 删除注册表键值
        
/// </summary>

        public static void DeleteRegistryKey()
        
{
            Microsoft.Win32.RegistryKey reg 
= Microsoft.Win32.Registry.CurrentUser;
            
string path=""Software\\"" + Application.ProductName;

//            reg.DeleteSubKeyTree(path);
            reg.DeleteSubKey(path);
            reg.Close();
        }
"
posted @ 2006-08-28 16:16  快乐的老毛驴  阅读(161)  评论(0编辑  收藏  举报