logonuser api returns 127

From: Brent Burkart (Brent.Burkart_at_wvmb.com)
Date: 03/11/04


Date: Thu, 11 Mar 2004 13:53:12 -0700

I have an impersonation procedure which was working before, but not any
more. It is returning a 127. Any help is appreciated.

 Here is the code.

'First the call to the routine
If Impersonate.impersonateValidUser("xxx", "xxx", "xxx") Then

    undoImpersonation()

Else

End If

'The routine

Declare Auto Function LogonUser Lib "advapi32.dll" (ByVal lpszUsername As
String, ByVal lpszDomain As String, ByVal lpszPassword As String, ByVal
dwLogonType As Integer, ByVal dwLogonProvider As Integer, ByRef phToken As
IntPtr) As Integer

Declare Auto Function ImpersonateLoggedOnUser Lib "advapi32.dll" (ByVal
hToken As IntPtr) As Integer

Declare Auto Function RevertToSelf Lib "advapi32.dll" () As Integer

Declare Auto Function GetLastError Lib "Kernel32.dll" () As Integer

Function impersonateValidUser(ByVal username As String, ByVal Domain As
String, ByVal password As String) As Boolean

Dim LogonType As Integer

Dim LogonProvider As Integer

Dim Tk As IntPtr

LogonType = 2 'Interactive

LogonProvider = 0 'Default Provider

If LogonUser(username, Domain, password, LogonType, LogonProvider, Tk) <> 0
Then

If ImpersonateLoggedOnUser(Tk) <> 0 Then

impersonateValidUser = True

Else

impersonateValidUser = False

End If

Else

Dim ret As Integer = GetLastError()

MsgBox(ret)

End If

End Function



Relevant Pages

  • Re: logonuser api returns 127
    ... > String, ByVal lpszDomain As String, ByVal lpszPassword As String, ByVal ... > Dim LogonProvider As Integer ... > impersonateValidUser = False ... are you absolutely sure that GetLastError is returning ...
    (microsoft.public.dotnet.languages.vb)
  • Can I use a windows mobile variant of this code to create a vaild
    ... Declare Function LogonUserA Lib "advapi32.dll" (ByVal lpszUsername As ... ByVal lpszDomain As String, _ ... Declare Auto Function RevertToSelf Lib "advapi32.dll" As Long ... Dim LOGON32_LOGON_INTERACTIVE As Integer = 2 ...
    (microsoft.public.sqlserver.security)
  • problems with Impersonate
    ... String, ByVal lpszDomain As String, ByVal lpszPassword As String, ByVal ... Declare Auto Function RevertToSelf Lib "advapi32.dll" As Integer ... Sub Main ...
    (microsoft.public.dotnet.languages.vb)
  • Re: problems with Impersonate
    ... String, ByVal lpszDomain As String, ByVal lpszPassword As String, ByVal ... Declare Auto Function RevertToSelf Lib "advapi32.dll" As Integer ... Sub Main ...
    (microsoft.public.dotnet.languages.vb)
  • Re: check a running process, impersonate
    ... Dim LOGON32_LOGON_INTERACTIVE As Integer = 2 ... Declare Auto Function LogonUser Lib "advapi32.dll" (ByVal lpszUsername As ... Public Sub Page_Load ... Private Function impersonateValidUser(userName As String, ...
    (microsoft.public.dotnet.framework.aspnet.security)

Loading