操作注册表类
#region 注册表类
public class Reg
{
public static void SetSubKey(string key,string Value)
{
RegistryKey rkey = Registry.LocalMachine.OpenSubKey(@"SoftWare\xxx",true);
rkey.SetValue(key,Value);
rkey.Close();
}
public static string GetSubKey(string key)
{
try
{
RegistryKey rkey = Registry.LocalMachine.OpenSubKey(@"SoftWare\xxx",true);
string v = rkey.GetValue(key).ToString();
rkey.Close();
return v;
}
catch
{
throw new Exception("注册表中缺少键");
}
}
/// <summary>
/// 创建根节点
/// </summary>
public static void RegRoot()
{
RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SoftWare",true);
key.CreateSubKey("xxx");
key.Close();
}
}
#endregion
类相关的属性和方法:
RegistryKey RegSubKey = Registry.ClassesRoot.OpenSubKey(strKey, true);
RegistryKey RegCtrlKey = RegSubKey.CreateSubKey("Control");
RegCtrlKey.Close();
RegistryKey RegInProcSvr = RegSubKey.OpenSubKey("InProcServer32", true);
RegInProcSvr.SetValue("CodeBase", Assembly.GetExecutingAssembly().CodeBase);
RegInProcSvr.Close();
RegSubKey.Close();