static string GetShortcutPath(SysShell shell = null) { if (shell == null) { shell = new SysShell(); } var startup = shell.GetSpecialFolder("Startup"); return(Path.Combine(startup, "Espresso.lnk")); }
private void toggleWindowsStart_Click(object sender, RoutedEventArgs e) { UserSettings.StartWithWindows = (bool)this.toggleWindowsStart.IsChecked; var shell = new SysShell(); var shortcut = GetShortcutPath(shell); var executable = Assembly.GetExecutingAssembly() .GetName().CodeBase; if (UserSettings.StartWithWindows) { // create shortcut in startup items folder in start menu shell.CreateShortcut(shortcut, executable); } else { // remove shortcut if it exists File.Delete(shortcut); } UserSettings.Save(); }