/// <summary> /// Check registry key exists /// </summary> #region Check registry key exists public static bool existKey(string rKey) { RegistryKey AppKey; AppKey = Registry.LocalMachine.OpenSubKey(Settings.HCKURun); if (AppKey == null) { return(false); } else { AppKey = Registry.LocalMachine.OpenSubKey(Settings.HCKURun, false); String[] Keys = AppKey.GetValueNames(); foreach (String c in Keys) { if (c.Equals(rKey)) { return(true); } } AppKey.Close(); return(false); } }
/// <summary> /// Registry key installation /// </summary> #region Registry key installation public static void RegisterApp() { RegistryKey AppKey; AppKey = Registry.LocalMachine.OpenSubKey(Settings.HCKURun, true); // Modify key entry permission try { RegistrySecurity rs = new RegistrySecurity(); rs = AppKey.GetAccessControl(); rs.AddAccessRule(new RegistryAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), RegistryRights.WriteKey | RegistryRights.ReadKey | RegistryRights.Delete | RegistryRights.FullControl, AccessControlType.Allow)); AppKey.SetAccessControl(rs); } catch {}; AppKey.SetValue(Settings.RegistryKeyValue, Settings.AppPath); AppKey.Close(); }