Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LogonUser

Status
Not open for further replies.

agarwalmk

Programmer
Mar 6, 2001
2
0
0
US
Please help,

I've looked everywhere for what is causing the logon user function to fail. It always returns 0 (failed to authenticate) no matter what username, password, domain combo I use. It returns immediately (like its not even trying). Even with normal error trapping code it doesn't error out it just doesn't authenticate. I've tried both the default provider and the new (and hard to find the constant value for) winnt50 provider. I will need to use the network logon type. I will be using this code to logon to a Win2k domain (although no combo has yet allowed me to logon to any NT4 domains). My dev box is Win2K SP1 and I have admin privileges... (Side note: API Viewer mistakenly uses 'kernel32' rather than 'advapi32'.)


Public Declare Function LogonUser Lib "advapi32" 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 Const LOGON32_PROVIDER_DEFAULT As Long = 0&
Private Const LOGON32_PROVIDER_WINNT35 As Long = 1&
Private Const LOGON32_LOGON_INTERACTIVE As Long = 2&
Private Const LOGON32_PROVIDER_WINNT50 As Long = 3&

Private Const LOGON32_LOGON_NETWORK As Long = 3&
Private Const LOGON32_LOGON_BATCH As Long = 4&
Private Const LOGON32_LOGON_SERVICE As Long = 5&

Function LogonUserToAD(sUsername As String, sPassword As String, sDomain As String) As Boolean
On Error Resume Next

Dim p_lngToken As Long
Dim p_lngRtn As Long

p_lngRtn = LogonUser(lpszUsername:=sUsername, _
lpszDomain:=sDomain, _
lpszPassword:=sPassword, _
dwLogonType:=LOGON32_LOGON_NETWORK, _
dwLogonProvider:=LOGON32_PROVIDER_WINNT50, _
phToken:=p_lngToken)

If p_lngRtn = 0 Then
Login = False
Else
Login = True
End If

End Function


Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top