diff --git a/SuperLauncher/AutoStartHelper.cs b/SuperLauncher/AutoStartHelper.cs new file mode 100644 index 0000000..397c309 --- /dev/null +++ b/SuperLauncher/AutoStartHelper.cs @@ -0,0 +1,71 @@ +using Microsoft.Win32; +using System.Linq; + +namespace SuperLauncher +{ + public static class AutoStartHelper + { + private const string SuperLauncherPath = "C:\\Users\\Public\\below average\\Super Launcher\\SuperLauncherBootstrap.exe"; + private const string RelativeRunKeyPath = "\\Software\\Microsoft\\Windows\\CurrentVersion\\Run"; + public static AutoStartStatus Status { + get => GetStatus(); + set + { + if (value == AutoStartStatus.Enabled) Enable(); + if (value == AutoStartStatus.Disabled) Disable(); + } + } + private static string RunKeyPath + { + get + { + return RunAsHelper.GetOriginalInvokerSID() + RelativeRunKeyPath; + } + } + private static void Enable() + { + if (Status == AutoStartStatus.Enabled) return; + RegistryKey key = Registry.Users.OpenSubKey(RunKeyPath, true); + try + { + key.SetValue("Super Launcher", SuperLauncherPath); + } + finally + { + key.Close(); + } + } + private static void Disable() + { + if (Status == AutoStartStatus.Disabled) return; + RegistryKey key = Registry.Users.OpenSubKey(RunKeyPath, true); + try + { + key.DeleteValue("Super Launcher"); + } + finally + { + key.Close(); + } + } + private static AutoStartStatus GetStatus() + { + RegistryKey key = Registry.Users.OpenSubKey(RunKeyPath); + try + { + if (key.GetValueNames().Contains("Super Launcher")) return AutoStartStatus.Enabled; + return AutoStartStatus.Disabled; + } + finally + { + key.Close(); + } + } + public enum AutoStartStatus + { + Unknown = -1, + Disabled = 0, + Enabled = 1 + } + } +} \ No newline at end of file diff --git a/SuperLauncher/ModernLauncherCredentialUI.xaml.cs b/SuperLauncher/ModernLauncherCredentialUI.xaml.cs index 1800753..d0033e6 100644 --- a/SuperLauncher/ModernLauncherCredentialUI.xaml.cs +++ b/SuperLauncher/ModernLauncherCredentialUI.xaml.cs @@ -24,6 +24,7 @@ private void Window_Loaded(object sender, RoutedEventArgs e) TBUserName.Focus(); CBRememberMe.IsChecked = Settings.Default.RememberMe; CBElevate.IsChecked = Settings.Default.AutoElevate; + CBAutoStart.IsChecked = AutoStartHelper.Status == AutoStartHelper.AutoStartStatus.Enabled; if (CredentialManager.CredReadA( "Super Launcher", CredentialManager.CredType.CRED_TYPE_GENERIC, @@ -49,6 +50,7 @@ private void BtnOK_Click(object sender, RoutedEventArgs e) { Settings.Default.RememberMe = CBRememberMe.IsChecked.Value; Settings.Default.AutoElevate = CBElevate.IsChecked.Value; + AutoStartHelper.Status = CBAutoStart.IsChecked.Value ? AutoStartHelper.AutoStartStatus.Enabled : AutoStartHelper.AutoStartStatus.Disabled; if (TBUserName.Text != "" && !TBUserName.Text.Contains('\\')) TBUserName.Text = Environment.UserDomainName + "\\" + TBUserName.Text; if (!ShouldDisableUserInput() && Settings.Default.RememberMe) { diff --git a/SuperLauncher/ShellView.cs b/SuperLauncher/ShellView.cs index 7c0b1a3..70cc9d2 100644 --- a/SuperLauncher/ShellView.cs +++ b/SuperLauncher/ShellView.cs @@ -185,8 +185,8 @@ private void MIOpenWith_DropDownItemClicked(object sender, ToolStripItemClickedE { ComFolderView.GetFocusedItem(out int piItem); ComFolderView.Item(piItem, out nint ppidl); - Win32Interop.SHGetNameFromIDList(ppidl, Win32Interop.SIGDN.SIGDN_NORMALDISPLAY, out string filePath); - if (Directory.Exists(CurrentFolder)) filePath = Path.Combine(CurrentFolder, filePath); + Win32Interop.SHGetNameFromIDList(ppidl, Win32Interop.SIGDN.SIGDN_FILESYSPATH, out string filePath); + if (Directory.Exists(CurrentFolder)) filePath = Path.Combine(CurrentFolder, Path.GetFileName(filePath)); if (filePath == null) { Shared.StartProcess(processPath);