Feedback

Active Directory Gruppen Zugehörigkeit prüfen

Sprache: C#

Man kann die Gruppenzugehörigkeit auch mit der SID der Gruppe prüfen. Damit nicht durch anlegen einer lokalen Gruppe zu umgehen. Ist auch "offline" ohne DomainController abprüfbar.
System.Security.Principal.WindowsIdentity ident = 
       System.Security.Principal.WindowsIdentity.GetCurrent();
System.Security.Principal.WindowsPrincipal prin = 
        new System.Security.Principal.WindowsPrincipal(ident);

System.Threading.Thread.CurrentPrincipal = prin;
if (prin.IsInRole(new System.Security.Principal.SecurityIdentifier("S-1-45-44-46456-44564-456456-232")))
{
    //Code hier ausführen
}
System.Security.Principal.WindowsIdentity ident = 
       System.Security.Principal.WindowsIdentity.GetCurrent();
System.Security.Principal.WindowsPrincipal prin = 
        new System.Security.Principal.WindowsPrincipal(ident);

System.Threading.Thread.CurrentPrincipal = prin;
if (prin.IsInRole(new System.Security.Principal.SecurityIdentifier("S-1-45-44-46456-44564-456456-232")))
{
    //Code hier ausführen
}