B
Brent Burkart
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
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