zoukankan      html  css  js  c++  java
  • .NET : 取得Windows账号的有关信息

    下面这个小程序演示了如何取得当前用户身份的相关信息

    using System;
    
    using System.Security.Principal;
    
    namespace ConsoleApplication1
    {
        class Program
        {
    
            /// <summary>
            /// 这个程序演示了如何获得当前Windows账号的相关信息
            /// 作者:陈希章
            /// </summary>
            /// <param name="args"></param>
            static void Main(string[] args)
            {
                AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
                WindowsIdentity identity = System.Threading.Thread.CurrentPrincipal.Identity as WindowsIdentity;
                Console.WriteLine("SID:{0}",identity.User.ToString());
                Console.WriteLine("Name:{0}",identity.Name);
                Console.WriteLine("IsSystem:{0}",identity.IsSystem);
                Console.WriteLine("AuthenticationType:{0}",identity.AuthenticationType);
                Console.WriteLine("Groups:{0}", identity.Groups.Count);
    
                Console.WriteLine("Group SID:");
                foreach (var item in identity.Groups)
                {
                    Console.WriteLine("\t{0}",item.Value);
                }
    
                Console.WriteLine("Group Name:");
                foreach (var item in identity.Groups.Translate(typeof(NTAccount)))
                {
                    Console.WriteLine("\t{0}",item.Value);
                }
                Console.Read();
    
            }
        }
    }
    

    image

  • 相关阅读:
    Jmeter beanshell preprocessor随机添加任意多个请求参数
    Jmeter 场景设计
    jmeter 参数化
    .net 匿名方法
    jmeter 运行脚本报错 java.net.BindException: Address already in use
    Jmeter mysql性能测试
    ngcordova 监控网络制式改变
    建立apk定时自动打包系统第一篇——Ant多渠道打包并指定打包目录和打包日期
    Kafka架构
    Linux命令
  • 原文地址:https://www.cnblogs.com/chenxizhang/p/1627927.html
Copyright © 2011-2022 走看看