C# WinForm 註冊表

        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);
        }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章