Currently, I\'m working in one migration request, where we need to change the framework from 3.5 to 4.6.2. Here the problem is after changing the framework below method is not s
I suspect that the problem may be related to the use of Environment.UserName
. Try replacing that with WindowsIdentity.GetCurrent()
, thus:
Shared Function UserInRole(role As String) As Boolean
Dim currPrincipal As New WindowsPrincipal(WindowsIdentity.GetCurrent())
Return currPrincipal.IsInRole(role)
End Function
However, it is worth remembering that User Account Control can get in the way. If you aren't running elevated then the above won't work for the WindowsBuiltInRole.Administrator
, possibly others. So that might be an issue as well. So worth seeing if you get different results when you run elevated.