Best way to check if a User is in Admin group

O

Olegus

Not sure this is right group to post my question.
What is the best way to check that current logged in user has local
admin/domain admin rights on a computer?
My application needs to be ran under admin account so I need to warn
user if it does not.

Thanks.
 
S

Smithers

The following method should get you moving in a good direction. It was
inspired from the listing at
http://www.oreillynet.com/windows/blog/2005/09/getting_the_windows_groups_of.html


private static List<string> GetWindowGroupsFromToken()
{
WindowsIdentity id = WindowsIdentity.GetCurrent();
List<string> groups = new List<string>();

IdentityReferenceCollection irc = id.Groups.Translate(typeof(NTAccount));

foreach (NTAccount acc in irc)
{
groups.Add(acc.Value.ToUpper());
}

return groups;

}


HTH

-"Smithers"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top