获取当前登陆window用户的一些信息

发布时间:2014-10-25 2:20:47
来源:分享查询网

 using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading;using System.Security.Principal; namespace ConsoleApplication1{    class Program    {        static void Main(string[] args)        {            AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);             WindowsPrincipal principal = (WindowsPrincipal)Thread.CurrentPrincipal;             WindowsIdentity identity=(WindowsIdentity)principal.Identity;             Console.WriteLine("IdentityType:" + identity.ToString());             Console.WriteLine("Name:{0}", identity.Name);             Console.WriteLine("Users?:{0}",principal.IsInRole("OBRUCH-COWGE//Administrator"));             Console.WriteLine("Administrators?{0}",                principal.IsInRole(WindowsBuiltInRole.Administrator));             Console.WriteLine("Authenticated:{0}", identity.IsAuthenticated);             Console.WriteLine("AuthType {0}", identity.AuthenticationType);             Console.WriteLine("Anonymous?{0}", identity.IsAnonymous);             Console.WriteLine("Token:{0}", identity.Token);         }    }}

返回顶部
查看电脑版