RegistryKey Setting - CSharp Operating System

CSharp examples for Operating System:Windows

Description

RegistryKey Setting

Demo Code


using Microsoft.Win32;
using System.Windows.Forms;
using System;/*from w w  w .  jav a2  s  .c  o  m*/

public class Main{
        public static void Setting(string sKeyName, object oKeyValue)
        {
            try
            {
                if ((oKeyValue == null) || (oKeyValue.ToString() == ""))
                {
                    RegistryKey.SetValue(sKeyName, string.Empty, RegistryValueKind.String);
                    RegistryKey.DeleteValue(sKeyName);
                }
                else
                    RegistryKey.SetValue(sKeyName, oKeyValue.ToString());
            }
            catch
            {
                // ignored
            }
        }
        public static string Setting(string sKeyName)
        {
            string sVal = null;

            try
            {
                sVal = RegistryKey.GetValue(sKeyName, string.Empty).ToString();
            }
            catch
            {
                // ignored
            }

            return string.IsNullOrEmpty(sVal) ? string.Empty : sVal;
        }
}

Related Tutorials