Skip to content

Commit

Permalink
Unable to get original invoker's SID when AD is offline, retrieve bef…
Browse files Browse the repository at this point in the history
…ore re-launching instead.
  • Loading branch information
Dylan Bickerstaff committed Jul 12, 2024
1 parent 38a06ac commit 285de36
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
7 changes: 7 additions & 0 deletions SuperLauncher/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Diagnostics;
using System.Windows;

namespace SuperLauncher
{
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 14 additions & 4 deletions SuperLauncher/RunAsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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"
};
Expand All @@ -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,
Expand Down Expand Up @@ -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()
{
Expand Down

0 comments on commit 285de36

Please sign in to comment.