
LogonUser function declaration problem
Thank you to Guillermo for helping me find the function - Now on th problem
#2!
According to the documentation for LogonUser in MSDN, the function returns a
zero if it fails, and something non-zero if it is successfull. Mine (of
course) is returning zero.
Sooooo, I'm now calling GetLastError right after my LogonUser function and
guess what - it also returns zero. According to MSDN - a zero from
GetLastError means everthing was OK.
Here is the code from my class:
Private Declare Function LogonUser Lib "advapi32.dll" Alias "LogonUserA" _
(ByVal lpszUsername As String, ByVal lpszDomain As String, _
ByVal lpszPassword As String, ByVal dwLogonType As Long, _
ByVal dwLogonProvider As Long, phToken As Long) As Long
Private Declare Function GetLastError Lib "kernel32" () As Long
Private Const LOGON32_LOGON_BATCH = 4
Private Const LOGON32_PROVIDER_DEFAULT = 0
Public Function LogonNewUser(User As String, Domain As String, Password As
String) As Long
Dim Token As Long
Dim RetVal As Long
Dim LastError As Long
RetVal = LogonUser(User, Domain, Password, _
LOGON32_LOGON_BATCH,
LOGON32_PROVIDER_DEFAULT, _
Token)
LastError = GetLastError()
If RetVal = 0 Then
MsgBox "LogonUser API call failed. Last error was " &
CStr(LastError)
LogonNewUser = 0
Else
LogonNewUser = Token
End If
End Function
Any help would be appriciated
Matt