diff --git a/SuperLauncher/Program.cs b/SuperLauncher/Program.cs index 6c72a29..80cdff8 100644 --- a/SuperLauncher/Program.cs +++ b/SuperLauncher/Program.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +using System.Windows; namespace SuperLauncher { @@ -34,9 +35,15 @@ public static void Main(string[] arguments) { RunAsHelper.StartupProcedure(); ModernApplication = new(); + ModernApplication.DispatcherUnhandledException += ModernApplication_DispatcherUnhandledException; ModernApplication.Run(new ModernLauncher()); } } + private static void ModernApplication_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) + { + MessageBox.Show(e.Exception.Message + "\n\n" + e.Exception.StackTrace, "Super Launcher", MessageBoxButton.OK, MessageBoxImage.Error); + ModernApplicationShutdown(); + } public static void ModernApplicationShutdown() { ModernApplicationShuttingDown = true; diff --git a/SuperLauncher/RunAsHelper.cs b/SuperLauncher/RunAsHelper.cs index 87fcf77..1d0e932 100644 --- a/SuperLauncher/RunAsHelper.cs +++ b/SuperLauncher/RunAsHelper.cs @@ -8,13 +8,14 @@ namespace SuperLauncher public static class RunAsHelper { public const string InvokerArg = "/OriginalInvoker:"; + public const string InvokerSIDArg = "/OriginalInvokerSID:"; public static string SelfPath = Process.GetCurrentProcess().MainModule.FileName; public static void Restart() { ProcessStartInfo psi = new() { FileName = SelfPath, - Arguments = InvokerArg + GetOriginalInvokerDomainWithUserName(), + Arguments = InvokerArg + GetOriginalInvokerDomainWithUserName() + ' ' + InvokerSIDArg + GetOriginalInvokerSID().ToString(), UseShellExecute = true }; try { Process.Start(psi); } catch { return; } @@ -25,7 +26,7 @@ public static void Elevate() ProcessStartInfo psi = new() { FileName = SelfPath, - Arguments = InvokerArg + GetOriginalInvokerDomainWithUserName(), + Arguments = InvokerArg + GetOriginalInvokerDomainWithUserName() + ' ' + InvokerSIDArg + GetOriginalInvokerSID().ToString(), UseShellExecute = true, Verb = "RunAs" }; @@ -40,7 +41,7 @@ public static void RunAs(string DomainWithUserName, string Password) ProcessStartInfo psi = new() { FileName = SelfPath, - Arguments = InvokerArg + GetOriginalInvokerDomainWithUserName(), + Arguments = InvokerArg + GetOriginalInvokerDomainWithUserName() + ' ' + InvokerSIDArg + GetOriginalInvokerSID().ToString(), UseShellExecute = false, UserName = UserName, PasswordInClearText = Password, @@ -109,7 +110,16 @@ public static string GetCurrentDomainWithUserName() } public static SecurityIdentifier GetOriginalInvokerSID() { - return new WindowsIdentity(GetOriginalInvokerUPN()).User; + try + { + string invokerArg = Shared.GetArugement("OriginalInvokerSID"); + if (invokerArg != null) return new SecurityIdentifier(invokerArg); + return GetCurrentSID(); + } + catch + { + return null; + } } public static SecurityIdentifier GetCurrentSID() {