/// <summary> /// 打开SOFTWARE下的一个注册表项 /// </summary> /// <param name="keyPath">项路径, 以\分开.</param> private RegistryKey OpenRegistry(string keyPath) { string[] keys = keyPath.Split('\\'); RegistryKey temp; temp = SimsRoot.OpenSubKey(keys[0], IsWritable); if (temp == null) { return(null); } for (int i = 1; i < keys.Length; i++) { temp = temp.OpenSubKey(keys[i], IsWritable); if (temp == null) { return(null); } } return(temp); }
/// <summary> /// 打开SOFTWARE下的一个注册表项, 如果不存在, 则创建. /// </summary> /// <param name="keyPath">项路径, 以\分开.</param> private RegistryKey OpenCreateRegistry(string keyPath) { string[] keys = keyPath.Split('\\'); RegistryKey temp, tempBack; tempBack = SimsRoot; temp = SimsRoot.OpenSubKey(keys[0], IsWritable); if (temp == null) { tempBack.CreateSubKey(keys[0]); temp = tempBack.OpenSubKey(keys[0], IsWritable); } tempBack = temp; for (int i = 1; i < keys.Length; i++) { temp = temp.OpenSubKey(keys[i], IsWritable); if (temp == null) { tempBack.CreateSubKey(keys[i]); temp = tempBack.OpenSubKey(keys[i], IsWritable); } tempBack = temp; } return(temp); }