C# 注册表Regedit读写

时间:2021-11-19 06:23:23

注册表的读写

1、读

     public static string GetRegeditData()
        {
            //Win10 读写LocalMachine权限,没有访问权限
            RegistryKey hkml = Registry.CurrentUser;
            RegistryKey software = hkml.OpenSubKey("SOFTWARE", true);
            RegistryKey aimdir = software.OpenSubKey("EmailTool", true);
            if (aimdir==null)
            {
                return null;
            }
            object value = aimdir.GetValue("LastDate");
            return value==null?null:value.ToString();
        }

2、写

     public static bool CreateRegedit(string tovalue)
        {
            //Win10 读写LocalMachine权限,没有访问权限
            RegistryKey hklm = Registry.CurrentUser;
            RegistryKey software = hklm.OpenSubKey("SOFTWARE", true);
            RegistryKey aimdir = software.CreateSubKey("EmailTool");
            aimdir.SetValue("LastDate", tovalue);
            return true;
        }    

这只是简单的读写,提供给大家入门直接使用的方法。