private static void RegisterStartupApplicationImpl(string applicationName, string program, bool register, bool applyToAllUsers) { using (RegistryKey registryKey = StartupManager.GetRunKey(applyToAllUsers, true)) { if (register) { registryKey.SetValue(applicationName, program); } else { registryKey.DeleteValue(applicationName, false); } } }
/// <summary> Tests to determine if the specified application will start with Windows. </summary> /// <param name="applicationName"> Name of the application. </param> /// <param name="applyToAllUsers"> <c>true</c> to check if enabled for all users, or <c>false</c> for the current. </param> /// <returns> /// <c>true</c> if the specified application will start with Windows, otherwise <c>false</c>. /// </returns> public static bool IsRegisteredForStartup(string applicationName, bool applyToAllUsers) { bool result; try { using (RegistryKey registryKey = StartupManager.GetRunKey(applyToAllUsers, false)) { result = Array.FindIndex(registryKey.GetValueNames(), name => string.Equals(name, applicationName, StringComparison.OrdinalIgnoreCase)) != -1; } } catch { result = false; } return(result); }