mirror of
https://github.com/wwiinnddyy/LanMountainDesktop.git
synced 2026-06-20 23:54:26 +08:00
31 lines
892 B
C#
31 lines
892 B
C#
using System.Security.Principal;
|
|
using LanMountainDesktop.Launcher.Models;
|
|
|
|
namespace LanMountainDesktop.Launcher.Infrastructure;
|
|
|
|
internal static class LauncherExecutionContext
|
|
{
|
|
public static LauncherExecutionSnapshot Capture()
|
|
{
|
|
var userName = Environment.UserName ?? string.Empty;
|
|
if (!OperatingSystem.IsWindows())
|
|
{
|
|
return new LauncherExecutionSnapshot(false, userName, null);
|
|
}
|
|
|
|
try
|
|
{
|
|
using var identity = WindowsIdentity.GetCurrent();
|
|
var principal = new WindowsPrincipal(identity);
|
|
return new LauncherExecutionSnapshot(
|
|
principal.IsInRole(WindowsBuiltInRole.Administrator),
|
|
userName,
|
|
identity.User?.Value);
|
|
}
|
|
catch
|
|
{
|
|
return new LauncherExecutionSnapshot(false, userName, null);
|
|
}
|
|
}
|
|
}
|