SetRegistData( "DisableTaskMgr", 7);
var getData = GetRegistData("DisableTaskMgr");
//getData == 7
public static object GetRegistData(string fild_name = "fild1", object defalut_fild_value = null)
{
string keypath = @"Software\test99_yhy_date";
RegistryKey hkml = Registry.CurrentUser;
RegistryKey aimdir = hkml.OpenSubKey(keypath, true);
if (aimdir != null)//路径不为null
{
object obj = aimdir.GetValue(fild_name, null);
if (obj != null) //字段不为null
return aimdir.GetValue(fild_name);
}
return defalut_fild_value;
}
public static void SetRegistData( string fild_name = "fild1", object fild_value = null)
{
string keypath = @"Software\test99_yhy_date";
RegistryKey hklm = Registry.CurrentUser;
RegistryKey aimdir = hklm.OpenSubKey(keypath, true);
if (aimdir == null)
{
aimdir = hklm.CreateSubKey(keypath);
}
aimdir.SetValue(fild_name, fild_value);
}