public void SetAutoStart(AutostartConfiguration config) { if (!this.CanWrite) { throw new InvalidOperationException("Don't have permission to write to the registry"); } logger.Info("Setting AutoStart to {0}", config); using (var registryKey = this.OpenRegistryKey(true)) { var keyExists = registryKey.GetValue(applicationName) != null; if (config.AutoStart) { var path = String.Format("\"{0}\"{1}", Assembly.GetExecutingAssembly().Location, config.StartMinimized ? " -minimized" : ""); logger.Debug("Autostart path: {0}", path); registryKey.SetValue(applicationName, path); } else if (keyExists) { logger.Debug("Removing pre-existing registry key"); registryKey.DeleteValue(applicationName); } } }
public AutostartConfiguration GetCurrentSetup() { if (!this.CanRead) { throw new InvalidOperationException("Don't have permission to read the registry"); } bool autoStart = false; bool startMinimized = false; using (var registryKey = this.OpenRegistryKey(false)) { var value = registryKey.GetValue(applicationName) as string; if (value != null) { autoStart = true; if (value.Contains(" -minimized")) { startMinimized = true; } } } var config = new AutostartConfiguration() { AutoStart = autoStart, StartMinimized = startMinimized }; logger.Info("GetCurrentSetup determined that the current configuration is: {0}", config); return(config); }
public void SetAutoStart(AutostartConfiguration config) { if (!this.CanWrite) throw new InvalidOperationException("Don't have permission to write to the registry"); logger.Info("Setting AutoStart to {0}", config); using (var registryKey = this.OpenRegistryKey(true)) { var keyExists = registryKey.GetValue(this.keyName) != null; if (config.AutoStart) { var path = String.Format("\"{0}\"{1}", this.assemblyProvider.Location, config.StartMinimized ? " -minimized" : ""); logger.Debug("Autostart path: {0}", path); registryKey.SetValue(this.keyName, path); } else if (keyExists) { logger.Debug("Removing pre-existing registry key"); registryKey.DeleteValue(this.keyName); } } }
public AutostartConfiguration GetCurrentSetup() { if (!this.CanRead) throw new InvalidOperationException("Don't have permission to read the registry"); bool autoStart = false; bool startMinimized = false; using (var registryKey = this.OpenRegistryKey(false)) { var value = registryKey.GetValue(this.keyName) as string; if (value != null) { autoStart = true; if (value.Contains(" -minimized")) startMinimized = true; } } var config = new AutostartConfiguration() { AutoStart = autoStart, StartMinimized = startMinimized }; logger.Info("GetCurrentSetup determined that the current configuration is: {0}", config); return config; }