ClassAssistance.Slave/Helper/WindowsHelper.cs

(完整代码) 1KB

using System;
using System.Security.Principal;

namespace ClassAssistance.Slave.Helper
{
    public static class WindowsHelper
    {
        static WindowsHelper()
        {
            using (var identity = WindowsIdentity.GetCurrent())
            {
                if (identity != null)
                {
                    AccountType = "Unknow";
                    var principal = new WindowsPrincipal(identity);
                    if (principal.IsInRole(WindowsBuiltInRole.Administrator))
                        AccountType = "Admin";
                    else if (principal.IsInRole(WindowsBuiltInRole.User))
                        AccountType = "User";
                    else if (principal.IsInRole(WindowsBuiltInRole.Guest))
                        AccountType = "Guest";
                }
            }
            UserName = Environment.UserName + $" ({AccountType})";
            MachineName = Environment.MachineName;
        }

        public static string UserName
        {
            get;
        }
        public static string MachineName
        {
            get;
        }
        public static string AccountType
        {
            get;
        }
    }
}

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。