Skip to content

Commit

Permalink
Added auto-start capibilities.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dylan Bickerstaff committed Jul 11, 2024
1 parent a2da1d7 commit 38a06ac
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 2 deletions.
71 changes: 71 additions & 0 deletions SuperLauncher/AutoStartHelper.cs
Original file line number Diff line number Diff line change
@@ -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
}
}
}
2 changes: 2 additions & 0 deletions SuperLauncher/ModernLauncherCredentialUI.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
{
Expand Down
4 changes: 2 additions & 2 deletions SuperLauncher/ShellView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 38a06ac

Please sign in to comment.