How to find if a user is administrator or not using C#

This code tells you if the user who is logged in is an administrator or not.

using System.Security.Principal;

bool IsAnAdministrator ()
{
   WindowsIdentity  identity = WindowsIdentity.GetCurrent();
   WindowsPrincipal principal = new WindowsPrincipal (identity);
   return principal.IsInRole(WindowsBuiltInRole.Administrator);
}
Advertisements

46 responses to this post.

  1. Again, invaluable report on a topic i have been trying to figure out…i am on adsense only, and making extremely little, will try out the rest. Many thanks!

  2. It’s truly a great and helpful piece of information. I’m happy that you simply shared this useful information with us. Please keep us up to date like this. Thank you for sharing.

  3. Helpfull post for me
    thanks quite much guys!!

  4. i’m jk its lovely

  5. The look for the weblog is a bit off in Epiphany. Even So I like your weblog. I might have to use a normal browser just to enjoy it.

  6. Re: The person who made the comment that this was a good web site really needs to get their head examined.

  7. Although I actually like this publish, I think there was an spelling error close to the finish of the third sentence.

  8. I love the site layout ! How do you make it!? It is rather sweet.

  9. If you could email me with a few hints & tips on how you made your blog look this good, Id appreciate it.

  10. You should really control the commentary on this website

  11. Just to let you know your website appears a little bit unusual in Firefox on my notebook using Linux .

  12. I experimented with looking at your website in my iphone and the design does not seem to be right. Might want to check it out on WAP as well as it seems most mobile phone layouts are not really working with your web site.

  13. Just discovered this blog thru Bing, what a way to brighten up my day!

  14. Have you given any thought at all with translating your blog into German? I know a several of translaters right here that would certainly help you do it for no cost if you want to get in touch with me personally.

  15. I was basically curious about if you ever considered switching the page layout of your blog? Its well written; I really like what youve got to say. But maybe you can create a a bit more in the way of content so people might connect with it better. Youve got a great deal of text for only having one or two graphics. Maybe you could space it out better?

  16. I enjoy your wordpress web template, where did you get a hold of it?

  17. This blog site is really cool. How can I make one like this .

  18. Wanted to drop a comment and let you know your Rss feed is not functioning today. I tried adding it to my Yahoo reader account and got nothing.

  19. Jesus Christ there is plenty of spammy feedback on this web site. Have you at any time thought about attempting to remove them or installing a extension?

  20. Re: The person who made the remark that this was an excellent site actually needs to have their brain reviewed.

  21. An cool blog post right there mate ! Thank you for that .

  22. Make money on new film releases! Meet the James Bond of Social Networking. Would you like to be the first person out of the gate to make money on feature film releases? http://www.nutvnetwork.com/paybackjackaffiliate.html

  23. I tried viewing your web site with my cellphone and the layout does not seem to be right. Might want to check it out on WAP as well as it seems most mobile phone layouts are not working with your website.

  24. When the Branch Davidians were burned out, someone commented that the government wasnt allowed to get involved with any religious group.

  25. You’re actually a just right webmaster. The web site loading speed is amazing. It kind of feels that you are doing any distinctive trick. In addition, The contents are masterpiece. you have performed a excellent process in this topic!

  26. Nice post my friend , just to let you know , i give you a google+1 also i share your link on my facebook timeline and my twitter account , keep writen .

  27. Good web site you have got here.. It’s difficult to find excellent writing like yours these days. I honestly appreciate individuals like you! Take care!!

  28. I have fun with, result in I found exactly what I was taking a look for. You have ended my four day lengthy hunt! God Bless you man. Have a nice day. Bye

  29. That you are the worst writer

  30. hi!,I love your writing so so much! share we be in contact more about your article on AOL? I require an expert on this area to resolve my problem. Maybe that’s you! Taking a look forward to look you.

  31. My sister sent me here and I’m happy! I will definitely favorite it and come back!

  32. This design is steller! You most certainly know how to keep a reader amused. Between your wit and your videos, I was almost moved to start my own blog (well, almost…HaHa!) Excellent job. I really loved what you had to say, and more than that, how you presented it. Too cool!

  33. Study it, liked it, thank you for it

  34. This is a great article! I like your ideas and your style. You have an uncanny ability to make the written word come to life. http://www.samsung1080phdtv.net/

  35. Howdy! This post couldn’t be written any better! Going through this article reminds me of my previous roommate! He continually kept preaching about this. I most certainly will forward this article to him. Fairly certain he’ll have a great read. I appreciate you for sharing!

  36. I¡¦ve been exploring for a little for any high-quality articles or weblog posts on this sort of space . Exploring in Yahoo I finally stumbled upon this website. Studying this info So i¡¦m happy to express that I have an incredibly excellent uncanny feeling I found out exactly what I needed. I such a lot certainly will make certain to do not disregard this site and provides it a glance regularly.

  37. Hmm it looks like your blog ate my first comment (it was extremely long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog.

    I as well am an aspiring blog blogger but I’m still new to everything. Do you have any suggestions for rookie blog writers? I’d definitely appreciate it.

  38. Very interesting subject, appreciate it for putting up.

  39. Individual salvation is based on the hands from the artistically maladjusted.

  40. Lets eradicate the idea of ‘childish’ simply because grownups normally result in the largest issues.

  41. Fantastic wordpress web site below.. It’s difficult to get top quality writing such as your own today. I seriously get pleasure from persons just like you! be cautious

  42. I take pleasure in, result in I discovered exactly what I
    used to be taking a look for. You’ve ended my four day lengthy hunt! God Bless you man. Have a nice day. Bye

  43. When you converse the truth, possess one particular feet in the stirrup.

  44. Wizard’s Tenth Concept: Willfully switching in addition to the facts are treason to help an individual’s do it yourself.

  45. just beneath, are various totally not connected websites to ours, on the other hand, they are certainly worth going over

Comments are closed.

%d bloggers like this: