Click to See Complete Forum and Search --> : impersonate


leran
May 16th, 2001, 03:52 AM
Hello.
Can anyone can tell me what is wrong with this code pls.
I just can't impersonate.
why?

...
...

Public Function Impersonate(UserName As String, Domain As String, Password As String, LogonType As Long, LogonProvider As Long)
Dim bOk As Long
Dim Token As Long

'called before LogonUser and ImpersonateLoggedOnUser to ensure that the
'current security context has the ability to impersonate.
'If you are already impersonated, which you are from ASP, you most likely do
'not have the necessary authority to impersonate.
bOk = RevertToUser

If bOk Then

'The LogonUser function receives the logon information (user ID, password, and so on)
'and returns the security token for a valid logon.
bOk = LogonUser(UserName, Domain, Password, LogonType, LogonProvider, Token)

If bOk Then
'The ImpersonateLoggedOnUser function receives the security token
'from LogonUser and applies it to the current thread.
bOk = ImpersonateLoggedOnUser(Token)
End If

End If

'The CloseHandle function closes an open object handle.
CloseHandle (Token)

Impersonate = bOk
End Function
...
...