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

  • 相关阅读:
    shell 去除utf8文件中bom头的方法
    bad interpreter:No such file or directory
    桥接配置虚拟机网络
    coreseek因为重启遇到的问题
    监听微信内置浏览器 返回点击事件
    phpredis 扩展装完后,重启php不生效的原因之一
    linux上ThinkPHP中原本正常的css,js文件找不到的解决方式
    vps
    java基础-《JAVA语言程序设计与数据结构》笔记
    面经问题总结——django相关
  • 原文地址:https://www.cnblogs.com/chenxizhang/p/1627927.html
Copyright © 2011-2022 走看看