Exemplo n.º 1
0
 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);
         }
     }
 }
Exemplo n.º 2
0
        /// <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);
        }
Exemplo n.º 3
0
 /// <summary> Unregisters the current process from starting with Windows. </summary>
 /// <param name="applicationName">  Name of the application. </param>
 /// <param name="applyToAllUsers"> <c>true</c> to unregister for all users, <c>false</c> to
 ///  unregister for the current user only. </param>
 public static void UnregisterStartupApplication(string applicationName, bool applyToAllUsers)
 {
     StartupManager.RegisterStartupApplicationImpl(applicationName, null, false, applyToAllUsers);
 }
Exemplo n.º 4
0
 /// <summary> Unregisters the current process from starting with Windows for the current user. </summary>
 public static void UnregisterStartupApplication()
 {
     StartupManager.UnregisterStartupApplication(Application.ProductName, false);
 }
Exemplo n.º 5
0
 /// <summary> Registers the specifies application to start with Windows. </summary>
 /// <param name="applicationName">  Name of the application. </param>
 /// <param name="program">  The program. </param>
 /// <param name="applyToAllUsers"> <c>true</c> to register for all users, <c>false</c> to
 ///   register for the current user only. </param>
 public static void RegisterStartupApplication(string applicationName, string program, bool applyToAllUsers)
 {
     StartupManager.RegisterStartupApplicationImpl(applicationName, program, true, applyToAllUsers);
 }
Exemplo n.º 6
0
 /// <summary> Registers the current process to start with Windows for the current user. </summary>
 public static void RegisterStartupApplication()
 {
     StartupManager.RegisterStartupApplication(Application.ProductName, "\"" + Application.ExecutablePath + "\"", false);
 }
Exemplo n.º 7
0
 /// <summary> Tests to determine if the specified application will start with Windows. </summary>
 /// <param name="applicationName">  Name of the application. </param>
 /// <returns>
 /// <c>true</c> if the specified application will start with Windows, otherwise <c>false</c>.
 /// </returns>
 public static bool IsRegisteredForStartup(string applicationName)
 {
     return(StartupManager.IsRegisteredForStartup(applicationName, false));
 }
Exemplo n.º 8
0
 /// <summary> Tests to determine if the current process will start with Windows. </summary>
 /// <returns> <c>true</c> if the current process will start with Windows, otherwise <c>false</c>. </returns>
 public static bool IsRegisteredForStartup()
 {
     return(StartupManager.IsRegisteredForStartup(Application.ProductName));
 }
Exemplo n.º 9
0
 private static RegistryKey GetRunKey(bool applyToAllUsers, bool writable)
 {
     return(StartupManager.GetHive(applyToAllUsers).OpenSubKey(_runKeyPath, writable));
 }