public static StartupEntry[] EnumerateEntries() { List<StartupEntry> entries = new List<StartupEntry>(); RegistryKey RegKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"); try { foreach (string itm in RegKey.GetValueNames()) { StartupEntry sEntry = new StartupEntry(); string value = RegKey.GetValue(itm).ToString(); sEntry.Application = itm; sEntry.Path = value; sEntry.Validity = EntryValidity.AllUsersX64; entries.Add(sEntry); } } catch { } RegistryKey RegKey2 = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run"); try { foreach (string itm in RegKey2.GetValueNames()) { StartupEntry sEntry = new StartupEntry(); string value = RegKey2.GetValue(itm).ToString(); sEntry.Application = itm; sEntry.Path = value; sEntry.Validity = EntryValidity.AllUsersX86; entries.Add(sEntry); } } catch { } RegistryKey RegKey3 = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run"); try { foreach (string itm in RegKey3.GetValueNames()) { StartupEntry sEntry = new StartupEntry(); string value = RegKey3.GetValue(itm).ToString(); sEntry.Application = itm; sEntry.Path = value; sEntry.Validity = EntryValidity.CurrentUser; entries.Add(sEntry); } } catch { } return entries.ToArray(); }
public static void CreateNewEntry(StartupEntry entry) { RegistryKey RegKey = null; if (entry.Validity == EntryValidity.AllUsersX64) { RegKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"); } else if (entry.Validity == EntryValidity.AllUsersX86) { RegKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run"); } else if (entry.Validity == EntryValidity.CurrentUser) { RegKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run"); } RegKey.SetValue(entry.Application, entry.Path, RegistryValueKind.String); return; }
public static void RemoveEntry(StartupEntry entry) { RegistryKey RegKey = null; if (entry.Validity == EntryValidity.AllUsersX64) { RegKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"); } else if (entry.Validity == EntryValidity.AllUsersX86) { RegKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run"); } else if (entry.Validity == EntryValidity.CurrentUser) { RegKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run"); } try { RegKey.DeleteValue(entry.Application); } catch { } }
/// <summary> /// Creates a new startup entry. /// </summary> /// <param name="entry"></param> public static void CreateNewEntry(StartupEntry entry) { RegistryKey regKey = null; if (entry.Validity == EntryValidity.AllUsersX64) { regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", RegistryKeyPermissionCheck.ReadWriteSubTree); } else if (entry.Validity == EntryValidity.AllUsersX86) { regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Run", RegistryKeyPermissionCheck.ReadWriteSubTree); } else if (entry.Validity == EntryValidity.CurrentUser) { regKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", RegistryKeyPermissionCheck.ReadWriteSubTree); } regKey.SetValue(entry.Application, entry.Path, RegistryValueKind.String); return; }
/// <summary> /// Removes an existing startup entry. /// </summary> /// <param name="entry"></param> public static void RemoveEntry(StartupEntry entry) { RegistryKey regKey = null; if (entry.Validity == EntryValidity.AllUsersX64) { regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", RegistryKeyPermissionCheck.ReadWriteSubTree); } else if (entry.Validity == EntryValidity.AllUsersX86) { regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Run", RegistryKeyPermissionCheck.ReadWriteSubTree); } else if (entry.Validity == EntryValidity.CurrentUser) { regKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", RegistryKeyPermissionCheck.ReadWriteSubTree); } regKey.DeleteValue(entry.Application); }