IsInRole says I'm a User, not an Administrator
Posted on 2011-09-27
I want to put code into my VB 2008 app to see whether the user is an Administrator or not. I've tried three different methods, and all are reporting that I'm not an Administrator (I'm just a User), even though Control Panel/Users clearly reports that I'm an Administrator. Further testing indicates that I get this result on Windows 7 (I've checked two different machines, one Win7 Home Premium and the other Win7 Pro), but with XP I get the proper Administrator response.
I've tried the following methods of checking (based on different suggestions I've seen on EE):
2) Dim idMe As WindowsIdentity = WindowsIdentity.GetCurrent
Dim prinMe As New WindowsPrincipal(idMe)
If prinMe.IsInRole(WindowsBuiltInRole.Administrator) Then
Dim WP As WindowsPrincipal
WP = System.Threading.Thread.CurrentPrincipal
If WP.IsInRole(WindowsBuiltInRole.Administrator) Then
Everything is reporting False. They all report true for WindowsBuiltInRole.User. Any ideas on why? Is there something different I should be doing on Win7?