Files
KJD/MAX.Framework/Helpers/SystemHelper.cs
T
2026-09-11 19:11:12 +08:00

39 lines
665 B
C#

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
namespace MAX.Framework.Helpers;
public class SystemHelper
{
public static bool IsAdministratorSafe
{
get
{
try
{
return IsAdministrator;
}
catch (Exception ex)
{
Debug.WriteLine(ex);
return false;
}
}
}
public static bool IsAdministrator
{
get
{
WindowsIdentity current = WindowsIdentity.GetCurrent();
WindowsPrincipal windowsPrincipal = new(current);
return windowsPrincipal.IsInRole(WindowsBuiltInRole.Administrator);
}
}
}