-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dylan Bickerstaff
committed
Jul 11, 2024
1 parent
a2da1d7
commit 38a06ac
Showing
3 changed files
with
75 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters