Get some security informations

Description :

We can get the some security information details of the current system

Following name spaces are used to get details

using System.Security.Principal;
using System.Threading;

Following is code details

WindowsPrincipal MyPrincipal = (WindowsPrincipal)Thread.CurrentPrincipal;
WindowsIdentity MyIdentity = (WindowsIdentity)MyPrincipal.Identity;
Console.WriteLine("IdentityType: " + MyIdentity.ToString());
Console.WriteLine("Name: " + MyIdentity.Name);
Console.WriteLine("Users?: " + MyPrincipal.IsInRole("BUILTIN\\Users"));
Console.WriteLine("Administrators?: " + MyPrincipal.IsInRole(WindowsBuiltInRole.Administrator));
Console.WriteLine("Authenticated: " + MyIdentity.IsAuthenticated);
Console.WriteLine("AuthType: " + MyIdentity.AuthenticationType);
Console.WriteLine("Anonymous?: " + MyIdentity.IsAnonymous);
Console.WriteLine("Token: " + MyIdentity.Token);

Code Explanation

1. Set Principal Policy
2. Create the instance of WindowsPrincipal
3. Create the instance of WindowsIdentity
4. Get the required values



No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: