we are using this VB.NET code inside a class since many years for testing if a given user is an administrator (shortened for clarity, error checking removed):
Private Declare Auto Function LogonUser Lib "advapi32.dll" (ByVal lpszUsername As String, ByVal lpszDomain As String, ByVal lpszPassword As String, ByVal dwLogonType As UInteger, ByVal dwLogonProvider As UInteger, ByRef phToken As IntPtr) As Boolean
Private token As IntPtr
Private identity As WindowsIdentity
Private principal As WindowsPrincipal
LogonUser(username, domain, password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, token)
identity = New WindowsIdentity(token)
principal = New WindowsPrincipal(identity)
Return principal.IsInRole(ApplicationServices.BuiltInRole.Administrator)
This code returns True for administrator credentials. This code works in Windows XP, Vista and Windows 7. We are aware of the fact that this code is not compatible with UAC turned on. So for this code to work in Windows Vista and 7, we turn off UAC. In Windows 8, however, even when turning off UAC, administrator credentials are still recognized as restricted token (part of BuiltInRole.User). So we cant impersonate the administrator with "identity.Impersonate".
Any ideas what why this code has been broken on Windows 8?
Thanks Alex